Change some things to string_view
diff --git a/src/support/json.h b/src/support/json.h index 98e46b0..2d57fef 100644 --- a/src/support/json.h +++ b/src/support/json.h
@@ -467,13 +467,12 @@ private: // Unescape the input (UTF8) string into one of our internal strings (WTF16). - void unescapeIntoWTF16(char* str) { + void unescapeIntoWTF16(std::string_view str) { // TODO: Optimize the unescaped path? But it is impossible to avoid an // allocation here. std::stringstream ss; wasm::String::unescapeUTF8JSONtoWTF16(ss, str); - // TODO: Use ss.view() once we have C++20. - setString(ss.str()); + setString(ss.view()); } };
diff --git a/src/support/string.cpp b/src/support/string.cpp index d3fbcec..c410c70 100644 --- a/src/support/string.cpp +++ b/src/support/string.cpp
@@ -499,19 +499,18 @@ return true; } -std::ostream& unescapeUTF8JSONtoWTF16(std::ostream& os, const char* str) { - std::string_view view(str); +std::ostream& unescapeUTF8JSONtoWTF16(std::ostream& os, std::string_view str) { size_t i = 0; while (str[i]) { if (str[i] != '\\') { // Normal character, possibly a multi-byte UTF-8 sequence. - auto rest = view.substr(i); + auto rest = str.substr(i); auto u = takeWTF8CodePoint(rest); if (!u) { Fatal() << "Invalid UTF-8 in JSON string"; } writeWTF16CodePoint(os, *u); - i = view.size() - rest.size(); + i = str.size() - rest.size(); continue; } @@ -548,7 +547,7 @@ if (!str[i + 2] || !str[i + 3] || !str[i + 4] || !str[i + 5]) { Fatal() << "Invalid escaped JSON \\uXXXX"; } - unhex << std::hex << std::string_view(str + i + 2, 4); + unhex << std::hex << str.substr(i + 2, 4); unhex >> x; // Write out the results.
diff --git a/src/support/string.h b/src/support/string.h index 4e9d108..6b7b6a7 100644 --- a/src/support/string.h +++ b/src/support/string.h
@@ -128,7 +128,7 @@ bool isPrintableUTF8(std::string_view str); // Given a string of properly-escaped JSON in UTF8, unescape it into WTF16. -std::ostream& unescapeUTF8JSONtoWTF16(std::ostream& os, const char* str); +std::ostream& unescapeUTF8JSONtoWTF16(std::ostream& os, std::string_view str); } // namespace wasm::String