diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-08-19 22:23:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-19 22:23:47 +0200 |
commit | 88b436e6a9c98af7215bd115e1b7a3f1a1db99d3 (patch) | |
tree | f07cdd7f93ca26b84192d7b89f7b952e603ba5cf /src/util/serialize.cpp | |
parent | 7528986e4449febead9b18b6118f0b096f7cf800 (diff) | |
download | minetest-88b436e6a9c98af7215bd115e1b7a3f1a1db99d3.tar.gz minetest-88b436e6a9c98af7215bd115e1b7a3f1a1db99d3.tar.bz2 minetest-88b436e6a9c98af7215bd115e1b7a3f1a1db99d3.zip |
Code modernization: subfolders (#6283)
* Code modernization: subfolders
Modernize various code on subfolders client, network, script, threading, unittests, util
* empty function
* default constructor/destructor
* for range-based loops
* use emplace_back instead of push_back
* C++ STL header style
* Make connection.cpp readable in a pointed place + typo
Diffstat (limited to 'src/util/serialize.cpp')
-rw-r--r-- | src/util/serialize.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/util/serialize.cpp b/src/util/serialize.cpp index 75843cb1b..49db9cf85 100644 --- a/src/util/serialize.cpp +++ b/src/util/serialize.cpp @@ -156,8 +156,8 @@ std::string serializeWideString(const std::wstring &plain) writeU16((u8 *)buf, plain.size()); s.append(buf, 2); - for (u32 i = 0; i < plain.size(); i++) { - writeU16((u8 *)buf, plain[i]); + for (wchar_t i : plain) { + writeU16((u8 *)buf, i); s.append(buf, 2); } return s; @@ -246,8 +246,7 @@ std::string serializeJsonString(const std::string &plain) std::ostringstream os(std::ios::binary); os << "\""; - for (size_t i = 0; i < plain.size(); i++) { - char c = plain[i]; + for (char c : plain) { switch (c) { case '"': os << "\\\""; @@ -308,7 +307,9 @@ std::string deSerializeJsonString(std::istream &is) if (c == '"') { return os.str(); - } else if (c == '\\') { + } + + if (c == '\\') { c2 = is.get(); if (is.eof()) throw SerializationError("JSON string ended prematurely"); @@ -390,17 +391,18 @@ std::string deSerializeJsonStringIfNeeded(std::istream &is) // Found end of word is.unget(); break; - } else { - tmp_os << c; } + + tmp_os << c; } expect_initial_quote = false; } if (is_json) { std::istringstream tmp_is(tmp_os.str(), std::ios::binary); return deSerializeJsonString(tmp_is); - } else - return tmp_os.str(); + } + + return tmp_os.str(); } //// |