Skip to content

Commit 132c739

Browse files
committed
Merge branch 'development' into dev14-rebase2
2 parents cda5888 + d8f0b3f commit 132c739

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

Release/include/cpprest/asyncrt_utils.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/***
22
* ==++==
33
*
4-
* Copyright (c) Microsoft Corporation. All rights reserved.
4+
* Copyright (c) Microsoft Corporation. All rights reserved.
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,7 +30,7 @@
3030
#if defined(_MSC_VER) && (_MSC_VER >= 1800)
3131
#include <ppltasks.h>
3232
namespace pplx = Concurrency;
33-
#else
33+
#else
3434
#include "pplx/pplxtasks.h"
3535
#endif
3636

Release/src/json/json_parsing.cpp

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/***
22
* ==++==
33
*
4-
* Copyright (c) Microsoft Corporation. All rights reserved.
4+
* Copyright (c) Microsoft Corporation. All rights reserved.
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -31,14 +31,14 @@
3131
#include <array>
3232

3333
#if defined(_MSC_VER)
34-
#pragma warning(disable : 4127) // allow expressions like while(true) pass
34+
#pragma warning(disable : 4127) // allow expressions like while(true) pass
3535
#endif
3636
using namespace web;
3737
using namespace web::json;
3838
using namespace utility;
3939
using namespace utility::conversions;
4040

41-
std::array<signed char,128> _hexval = {{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
41+
std::array<signed char,128> _hexval = {{ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4242
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4343
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
4444
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
@@ -74,7 +74,7 @@ template <typename CharType>
7474
class JSON_Parser
7575
{
7676
public:
77-
JSON_Parser()
77+
JSON_Parser()
7878
: m_currentLine(1),
7979
m_eof(std::char_traits<CharType>::eof()),
8080
m_currentColumn(1),
@@ -171,15 +171,15 @@ class JSON_Parser
171171
void CreateToken(typename JSON_Parser<CharType>::Token& tk, typename Token::Kind kind, Location &start)
172172
{
173173
tk.kind = kind;
174-
tk.start = start;
174+
tk.start = start;
175175
tk.string_val.clear();
176176
}
177177

178178
void CreateToken(typename JSON_Parser<CharType>::Token& tk, typename Token::Kind kind)
179179
{
180180
tk.kind = kind;
181-
tk.start.m_line = m_currentLine;
182-
tk.start.m_column = m_currentColumn;
181+
tk.start.m_line = m_currentLine;
182+
tk.start.m_column = m_currentColumn;
183183
tk.string_val.clear();
184184
}
185185

@@ -405,16 +405,16 @@ namespace
405405
}
406406
#endif
407407

408-
static double anystod(const char* str)
408+
static double anystod(const char* str)
409409
{
410410
#ifdef _MS_WINDOWS
411411
return _strtod_l(str, nullptr, utility::details::scoped_c_thread_locale::c_locale());
412412
#else
413-
return strtod(str, nullptr);
413+
return strtod(str, nullptr);
414414
#endif
415415
}
416-
static double anystod(const wchar_t* str)
417-
{
416+
static double anystod(const wchar_t* str)
417+
{
418418
#ifdef _MS_WINDOWS
419419
return _wcstod_l(str, nullptr, utility::details::scoped_c_thread_locale::c_locale());
420420
#else
@@ -697,10 +697,20 @@ bool JSON_StringParser<CharType>::CompleteComment(typename JSON_Parser<CharType>
697697
return true;
698698
}
699699

700+
void convert_append_unicode_code_unit(JSON_Parser<wchar_t>::Token &token, char16_t value)
701+
{
702+
token.string_val.push_back(value);
703+
}
704+
void convert_append_unicode_code_unit(JSON_Parser<char>::Token &token, char16_t value)
705+
{
706+
utf16string utf16(reinterpret_cast<utf16char *>(&value), 1);
707+
token.string_val.append(::utility::conversions::utf16_to_utf8(utf16));
708+
}
709+
700710
template <typename CharType>
701711
inline bool JSON_Parser<CharType>::handle_unescape_char(Token &token)
702712
{
703-
// This function converts unescape character pairs (e.g. "\t") into their ASCII or UNICODE representations (e.g. tab sign)
713+
// This function converts unescape character pairs (e.g. "\t") into their ASCII or Unicode representations (e.g. tab sign)
704714
// Also it handles \u + 4 hexadecimal digits
705715
CharType ch = NextCharacter();
706716
switch (ch)
@@ -731,7 +741,8 @@ inline bool JSON_Parser<CharType>::handle_unescape_char(Token &token)
731741
return true;
732742
case 'u':
733743
{
734-
// A four-hexdigit unicode character
744+
// A four-hexdigit Unicode character.
745+
// Transform into a 16 bit code point.
735746
int decoded = 0;
736747
for (int i = 0; i < 4; ++i)
737748
{
@@ -755,8 +766,8 @@ inline bool JSON_Parser<CharType>::handle_unescape_char(Token &token)
755766
}
756767

757768
// Construct the character based on the decoded number
758-
ch = static_cast<CharType>(decoded & 0xFFFF);
759-
token.string_val.push_back(ch);
769+
convert_append_unicode_code_unit(token, static_cast<char16_t>(decoded));
770+
760771
return true;
761772
}
762773
default:
@@ -966,14 +977,14 @@ std::unique_ptr<web::json::details::_Object> JSON_Parser<CharType>::_ParseObject
966977
auto obj = utility::details::make_unique<web::json::details::_Object>(g_keep_json_object_unsorted);
967978
auto& elems = obj->m_object.m_elements;
968979

969-
if ( tkn.kind != JSON_Parser<CharType>::Token::TKN_CloseBrace )
980+
if ( tkn.kind != JSON_Parser<CharType>::Token::TKN_CloseBrace )
970981
{
971982
while ( true )
972983
{
973984
// State 1: New field or end of object, looking for field name or closing brace
974985

975986
std::basic_string<CharType> fieldName;
976-
987+
977988
switch ( tkn.kind )
978989
{
979990
case JSON_Parser<CharType>::Token::TKN_StringLiteral:
@@ -1038,7 +1049,7 @@ std::unique_ptr<web::json::details::_Array> JSON_Parser<CharType>::_ParseArray(t
10381049

10391050
auto result = utility::details::make_unique<web::json::details::_Array>();
10401051

1041-
if ( tkn.kind != JSON_Parser<CharType>::Token::TKN_CloseBracket )
1052+
if ( tkn.kind != JSON_Parser<CharType>::Token::TKN_CloseBracket )
10421053
{
10431054
while ( true )
10441055
{
@@ -1096,7 +1107,7 @@ std::unique_ptr<web::json::details::_Value> JSON_Parser<CharType>::_ParseValue(t
10961107
return std::move(value);
10971108
}
10981109

1099-
case JSON_Parser<CharType>::Token::TKN_NumberLiteral:
1110+
case JSON_Parser<CharType>::Token::TKN_NumberLiteral:
11001111
{
11011112
auto value = utility::details::make_unique<web::json::details::_Number>(tkn.double_val);
11021113
GetNextToken(tkn);

Release/tests/functional/json/parsing_tests.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/***
22
* ==++==
33
*
4-
* Copyright (c) Microsoft Corporation. All rights reserved.
4+
* Copyright (c) Microsoft Corporation. All rights reserved.
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
77
* You may obtain a copy of the License at
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -202,13 +202,21 @@ TEST(string_t)
202202

203203
str = json::value::parse(U("\"\\t\""));
204204
VERIFY_ARE_EQUAL(U("\t"), str.as_string());
205+
}
205206

206-
str = json::value::parse(U("\"\\u0041\""));
207+
TEST(escaped_unicode_string)
208+
{
209+
auto str = json::value::parse(U("\"\\u0041\""));
207210
VERIFY_ARE_EQUAL(U("A"), str.as_string());
208211

209212
str = json::value::parse(U("\"\\u004B\""));
210213
VERIFY_ARE_EQUAL(U("K"), str.as_string());
211214

215+
str = json::value::parse(U("\"\\u20AC\""));
216+
// Euro sign as a hexidecmial UTF-8
217+
const auto euro = to_string_t("\xE2\x82\xAC");
218+
VERIFY_ARE_EQUAL(euro, str.as_string());
219+
212220
VERIFY_PARSING_THROW(json::value::parse(U("\"\\u0klB\"")));
213221
}
214222

@@ -565,7 +573,7 @@ TEST(keep_order_while_parsing)
565573
VERIFY_ARE_EQUAL(obj[U("a")].as_integer(), 4);
566574
}
567575

568-
TEST(non_default_locale, "Ignore:Apple", "263")
576+
TEST(non_default_locale)
569577
{
570578
std::string originalLocale = setlocale(LC_ALL, nullptr);
571579
#ifdef _MS_WINDOWS

0 commit comments

Comments
 (0)