From 2e9248670bd5600f75a17b430665cb2ae3f919a6 Mon Sep 17 00:00:00 2001 From: Jakub Skowron Date: Wed, 24 Jan 2018 09:44:34 +0100 Subject: [PATCH] [Filesystem] Remove special case for zero in readBytes/writeBytes Null character in Unicode sequence is correctly interpreted by picojson and crosswalk, so remove mapping 0 to 0x100. Change-Id: I61988a1089ecdab006ce5cc2492960d526fb9455 Signed-off-by: Jakub Skowron --- src/filesystem/filesystem_instance.cc | 21 ++++++++++----------- src/filesystem/js/file_stream.js | 21 +++++++-------------- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index eaceadc8..e6002749 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -137,26 +137,22 @@ void FilesystemInstance::FileRename(const picojson::value& args, picojson::objec std::bind(&FilesystemManager::Rename, &fsm, oldPath, newPath, onSuccess, onError)); } -/* str should be a reference to (possibly empty) std::string */ +/* Write to str buf bytes as if they were UTF-8 codepoints */ static void encode_binary_in_string(const std::vector& buf, std::string& str) { ScopeLogger(); str.reserve(str.size() + buf.size()); for (std::uint8_t byte : buf) { - if (byte >= 128) { - str += 0xC0 | (byte >> 6); - str += 0x80 | (byte & 0x3F); - } else if (byte > 0) { + if (byte < 128) { str += byte; - } else { - // zero as codepoint U+0100 - str += 0xC4; - str += 0x80; + continue; } + str += 0xC0 | (byte >> 6); + str += 0x80 | (byte & 0x3F); } } -/* buf should be a reference to (possibly empty) vector */ +/* Decode (max 2-byte) UTF-8 characters to buf, throws std::runtime_error */ static void decode_binary_from_string(const std::string& str, std::vector& buf) { ScopeLogger(); buf.reserve(buf.size() + str.size()); @@ -169,9 +165,12 @@ static void decode_binary_from_string(const std::string& str, std::vector