aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <mbuland@penny-arcade.com>2018-12-17 10:03:18 -0800
committerMike Buland <mbuland@penny-arcade.com>2018-12-17 10:03:18 -0800
commit4a541f7ba5306f9ebcc7f0fe2eeb663d3f527070 (patch)
tree4402b7d6c711fe79d30d33981a188d99d2c2c81b
parent3f67108249b5c4f97841beee18fdd761919fe754 (diff)
downloadlibbu++-4a541f7ba5306f9ebcc7f0fe2eeb663d3f527070.tar.gz
libbu++-4a541f7ba5306f9ebcc7f0fe2eeb663d3f527070.tar.bz2
libbu++-4a541f7ba5306f9ebcc7f0fe2eeb663d3f527070.tar.xz
libbu++-4a541f7ba5306f9ebcc7f0fe2eeb663d3f527070.zip
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.
-rw-r--r--src/tests/json.cpp2
-rw-r--r--src/unstable/json.cpp11
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 @@
5 5
6int main( int argc, char *argv[] ) 6int main( int argc, char *argv[] )
7{ 7{
8 Bu::Json j("Hi there"); 8 Bu::Json j( "\x01" "ACTION" "\x01" );
9 Bu::println( j.toString() ); 9 Bu::println( j.toString() );
10 return 0; 10 return 0;
11} 11}
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
747 break; 747 break;
748 748
749 default: 749 default:
750 sOutput.write( &(*i), 1 ); 750 if( *i < 32 )
751 sOutput.write(
752 Bu::String("\\u%1").
753 arg( (int32_t)*i, Bu::Fmt::hex(4).fill('0') ).
754 end().getStr(),
755 6
756 );
757 else
758 sOutput.write( &(*i), 1 );
759 break;
751 } 760 }
752 } 761 }
753 sOutput.write("\"", 1 ); 762 sOutput.write("\"", 1 );