Skip to content

Commit f5022ee

Browse files
committed
Libc++ on OSX does not provide std::ctype<char16_t>
We therefore cannot use char16_t based iostreams while under libc++.
1 parent 88cc67b commit f5022ee

File tree

6 files changed

+25
-3
lines changed

6 files changed

+25
-3
lines changed

Release/include/cpprest/asyncrt_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ namespace conversions
210210
}
211211
return t;
212212
}
213+
#if !defined(_LIBCPP_VERSION)
213214
template <typename Target>
214215
Target scan_string(const utf16string &str, const std::locale &loc = std::locale())
215216
{
@@ -223,6 +224,7 @@ namespace conversions
223224
}
224225
return t;
225226
}
227+
#endif
226228

227229
}
228230

Release/include/cpprest/details/basic_types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,15 @@ typedef std::wistringstream utf16istringstream;
116116
#else
117117
typedef char16_t utf16char;
118118
typedef std::u16string utf16string;
119+
// Libc++ does not define std::ctype<char16_t> which prevents the following streams from working.
120+
#if !defined(_LIBCPP_VERSION)
119121
typedef std::basic_stringstream<utf16char> utf16stringstream;
120122
typedef std::basic_ostringstream<utf16char> utf16ostringstream;
121123
typedef std::basic_ostream<utf16char> utf16ostream;
122124
typedef std::basic_istream<utf16char> utf16istream;
123125
typedef std::basic_istringstream<utf16char> utf16istringstream;
124126
#endif
127+
#endif
125128

126129

127130
#if defined(_WIN32)

Release/include/cpprest/json.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,9 @@ namespace json
527527
/// </summary>
528528
/// <param name="stream">The stream to read the JSON value from</param>
529529
_ASYNCRTIMP static value __cdecl parse(std::istream& stream);
530+
#if !defined(_LIBCPP_VERSION)
530531
_ASYNCRTIMP static value __cdecl parse(utf16istream& stream);
532+
#endif
531533

532534
/// <summary>
533535
/// Parses a JSON value from the contents of a single-byte (UTF8) stream.
@@ -536,7 +538,9 @@ namespace json
536538
/// <param name="errorCode">If parsing fails, the error code is greater than 0</param>
537539
/// <returns>The parsed object. Returns web::json::value::null if failed</returns>
538540
_ASYNCRTIMP static value __cdecl parse(std::istream& stream, std::error_code& error);
541+
#if !defined(_LIBCPP_VERSION)
539542
_ASYNCRTIMP static value __cdecl parse(utf16istream& stream, std::error_code& error);
543+
#endif
540544

541545
/// <summary>
542546
/// Serializes the current JSON value to a UTF-8 string.
@@ -555,13 +559,12 @@ namespace json
555559
#endif
556560
stream << serialize();
557561
}
562+
#if !defined(_LIBCPP_VERSION)
558563
inline void serialize(utf16ostream& stream) const
559564
{
560-
#ifndef _WIN32
561-
utility::details::scoped_c_thread_locale locale;
562-
#endif
563565
stream << utility::conversions::to_utf16string(serialize());
564566
}
567+
#endif
565568

566569
/// <summary>
567570
/// Serializes the content of the value into a UTF-8 string.
@@ -1790,10 +1793,12 @@ namespace json
17901793
val.serialize(os);
17911794
return os;
17921795
}
1796+
#if !defined(_LIBCPP_VERSION)
17931797
inline utf16ostream& operator << (utf16ostream &os, const json::value &val) {
17941798
val.serialize(os);
17951799
return os;
17961800
}
1801+
#endif
17971802

17981803
/// <summary>
17991804
/// A standard <c>std::istream</c> operator to facilitate reading JSON values from streams.
@@ -1805,10 +1810,12 @@ namespace json
18051810
val = ::web::json::value::parse(is);
18061811
return is;
18071812
}
1813+
#if !defined(_LIBCPP_VERSION)
18081814
inline utf16istream& operator >> (utf16istream &is, json::value &val) {
18091815
val = ::web::json::value::parse(is);
18101816
return is;
18111817
}
1818+
#endif
18121819
}}
18131820

18141821
#endif

Release/src/json/json_parsing.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ class JSON_StreamParser<char> : public JSON_Parser
246246
typename std::streambuf* m_streambuf;
247247
};
248248

249+
#if !defined(_LIBCPP_VERSION)
249250
template <>
250251
class JSON_StreamParser<utf16char> : public JSON_Parser
251252
{
@@ -333,6 +334,7 @@ class JSON_StreamParser<utf16char> : public JSON_Parser
333334
// The string of utf8 code units are buffered in reverse order
334335
std::string m_utf8_buffer;
335336
};
337+
#endif
336338

337339
class JSON_StringParser : public JSON_Parser
338340
{
@@ -1234,9 +1236,11 @@ static std::unique_ptr<web::json::details::JSON_Parser> parser_factory(std::istr
12341236
static std::unique_ptr<web::json::details::JSON_Parser> parser_factory(const std::string& str) {
12351237
return utility::details::make_unique<web::json::details::JSON_StringParser>(str);
12361238
}
1239+
#if !defined(_LIBCPP_VERSION)
12371240
static std::unique_ptr<web::json::details::JSON_Parser> parser_factory(utf16istream& stream) {
12381241
return utility::details::make_unique<web::json::details::JSON_StreamParser<utf16char>>(stream);
12391242
}
1243+
#endif
12401244

12411245
template<class Stream>
12421246
static web::json::value parse_stream(Stream&& stream, std::error_code& error)
@@ -1289,6 +1293,7 @@ web::json::value web::json::value::parse(const std::string& stream, std::error_c
12891293
return parse_stream(stream, error);
12901294
}
12911295

1296+
#if !defined(_LIBCPP_VERSION)
12921297
web::json::value web::json::value::parse(utf16istream& stream)
12931298
{
12941299
return parse_stream(stream);
@@ -1298,3 +1303,4 @@ web::json::value web::json::value::parse(utf16istream& stream, std::error_code&
12981303
{
12991304
return parse_stream(stream, error);
13001305
}
1306+
#endif

Release/tests/functional/json/negative_parsing_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ TEST(stream_left_over_chars)
156156
verify_json_throws(stream);
157157
}
158158

159+
#if !defined(_LIBCPP_VERSION)
159160
TEST(wstream_left_over_chars)
160161
{
161162
std::basic_stringbuf<utf16char> buf;
@@ -167,6 +168,7 @@ TEST(wstream_left_over_chars)
167168
utf16istream stream(&buf);
168169
verify_json_throws(stream);
169170
}
171+
#endif
170172

171173
void garbage_impl(wchar_t ch)
172174
{

Release/tests/functional/json/parsing_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,11 +667,13 @@ TEST(non_default_locale, "Ignore:Android", "Locale unsupported on Android")
667667
setlocale(LC_NUMERIC, changedLocale.c_str());
668668

669669
// cpprestsdk stream serialize
670+
#if !defined(_LIBCPP_VERSION)
670671
utf16stringstream stream;
671672
stream << v;
672673
utf16string serializedStr;
673674
stream >> serializedStr;
674675
VERIFY_ARE_EQUAL(utility::conversions::to_utf16string(str), serializedStr);
676+
#endif
675677

676678
// std stream serialize
677679
std::stringstream stdStream;

0 commit comments

Comments
 (0)