From 4a541f7ba5306f9ebcc7f0fe2eeb663d3f527070 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 17 Dec 2018 10:03:18 -0800 Subject: Bu::Json handles encoding control chars. It still needs to handle the rest of unicode properly. It'll require a minor change but shouldn't be too bad overall. --- src/tests/json.cpp | 2 +- src/unstable/json.cpp | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/tests/json.cpp b/src/tests/json.cpp index d588a02..6490d8d 100644 --- a/src/tests/json.cpp +++ b/src/tests/json.cpp @@ -5,7 +5,7 @@ int main( int argc, char *argv[] ) { - Bu::Json j("Hi there"); + Bu::Json j( "\x01" "ACTION" "\x01" ); Bu::println( j.toString() ); return 0; } diff --git a/src/unstable/json.cpp b/src/unstable/json.cpp index adc2706..06df9b1 100644 --- a/src/unstable/json.cpp +++ b/src/unstable/json.cpp @@ -747,7 +747,16 @@ void Bu::Json::writeStr( const Bu::String &sStr, Bu::Stream &sOutput ) const break; default: - sOutput.write( &(*i), 1 ); + if( *i < 32 ) + sOutput.write( + Bu::String("\\u%1"). + arg( (int32_t)*i, Bu::Fmt::hex(4).fill('0') ). + end().getStr(), + 6 + ); + else + sOutput.write( &(*i), 1 ); + break; } } sOutput.write("\"", 1 ); -- cgit v1.2.3