From: Jakub Skowron Date: Wed, 24 Jan 2018 08:44:34 +0000 (+0100) Subject: [Filesystem] Remove special case for zero in readBytes/writeBytes X-Git-Tag: submit/tizen_4.0/20180126.102411~3^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F19%2F168019%2F2;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [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 --- 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