Skip to content

Commit 6263d69

Browse files
committed
Making convert_append_unicode_code_unit function not part of JSON_Parser class and not be a template.
1 parent 7ffcb8f commit 6263d69

File tree

2 files changed

+15
-17
lines changed

2 files changed

+15
-17
lines changed

Release/src/json/json_parsing.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ class JSON_Parser
152152
virtual bool CompleteComment(Token &token);
153153
virtual bool CompleteStringLiteral(Token &token);
154154
bool handle_unescape_char(Token &token);
155-
void convert_append_unicode_code_unit(Token &token, char16_t value);
156-
155+
157156
private:
158157

159158
bool CompleteNumberLiteral(CharType first, Token &token);
@@ -693,10 +692,20 @@ bool JSON_StringParser<CharType>::CompleteComment(typename JSON_Parser<CharType>
693692
return true;
694693
}
695694

695+
void convert_append_unicode_code_unit(JSON_Parser<wchar_t>::Token &token, char16_t value)
696+
{
697+
token.string_val.push_back(value);
698+
}
699+
void convert_append_unicode_code_unit(JSON_Parser<char>::Token &token, char16_t value)
700+
{
701+
utf16string utf16(reinterpret_cast<utf16char *>(&value), 1);
702+
token.string_val.append(::utility::conversions::utf16_to_utf8(utf16));
703+
}
704+
696705
template <typename CharType>
697706
inline bool JSON_Parser<CharType>::handle_unescape_char(Token &token)
698707
{
699-
// This function converts unescape character pairs (e.g. "\t") into their ASCII or UNICODE representations (e.g. tab sign)
708+
// This function converts unescape character pairs (e.g. "\t") into their ASCII or Unicode representations (e.g. tab sign)
700709
// Also it handles \u + 4 hexadecimal digits
701710
CharType ch = NextCharacter();
702711
switch (ch)
@@ -727,7 +736,8 @@ inline bool JSON_Parser<CharType>::handle_unescape_char(Token &token)
727736
return true;
728737
case 'u':
729738
{
730-
// A four-hexdigit Unicode character
739+
// A four-hexdigit Unicode character.
740+
// Transform into a 16 bit code point.
731741
int decoded = 0;
732742
for (int i = 0; i < 4; ++i)
733743
{
@@ -760,19 +770,6 @@ inline bool JSON_Parser<CharType>::handle_unescape_char(Token &token)
760770
}
761771
}
762772

763-
template <typename CharType>
764-
inline void JSON_Parser<CharType>::convert_append_unicode_code_unit(Token &token, char16_t value)
765-
{
766-
token.string_val.push_back(value);
767-
}
768-
769-
template <>
770-
inline void JSON_Parser<char>::convert_append_unicode_code_unit(Token &token, char16_t value)
771-
{
772-
utf16string utf16(reinterpret_cast<utf16char *>(&value), 1);
773-
token.string_val.append(::utility::conversions::utf16_to_utf8(utf16));
774-
}
775-
776773
template <typename CharType>
777774
bool JSON_Parser<CharType>::CompleteStringLiteral(Token &token)
778775
{

Release/tests/Functional/json/parsing_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ TEST(escaped_unicode_string)
213213
VERIFY_ARE_EQUAL(U("K"), str.as_string());
214214

215215
str = json::value::parse(U("\"\\u20AC\""));
216+
// Euro sign as a hexidecmial UTF-8
216217
const auto euro = to_string_t("\xE2\x82\xAC");
217218
VERIFY_ARE_EQUAL(euro, str.as_string());
218219

0 commit comments

Comments
 (0)