Browse Source

[hxcpp] Allow hxcpp strings to be non-utf8

hughsando 7 years ago
parent
commit
a3b23fec8f
3 changed files with 12 additions and 4 deletions
  1. 9 1
      std/cpp/_std/StringBuf.hx
  2. 2 2
      std/haxe/format/JsonParser.hx
  3. 1 1
      std/haxe/xml/Parser.hx

+ 9 - 1
std/cpp/_std/StringBuf.hx

@@ -72,8 +72,16 @@ class StringBuf {
    }
 
    public #if !cppia inline #end function addChar( c : Int ) : Void {
-      if (charBuf==null) charBuf = new Array<cpp.Char>();
+      #if hxcpp_smart_strings
+      if (c>=127)
+         add(String.fromCharCode(c));
+      else
+      #end
+      {
+      if (charBuf==null)
+          charBuf = new Array<cpp.Char>();
       charBuf.push(c);
+      }
    }
 
    public function toString() : String {

+ 2 - 2
std/haxe/format/JsonParser.hx

@@ -172,7 +172,7 @@ class JsonParser {
 				case 'u'.code:
 					var uc = Std.parseInt("0x" + str.substr(pos, 4));
 					pos += 4;
-					#if (neko || php || cpp || lua || eval)
+					#if (neko || php || (cpp&&!hxcpp_smart_strings) || lua || eval)
 					if( uc <= 0x7F )
 						buf.addChar(uc);
 					else if( uc <= 0x7FF ) {
@@ -196,7 +196,7 @@ class JsonParser {
 				}
 				start = pos;
 			}
-			#if (neko || php || cpp)
+			#if (neko || php || (cpp&&!hxcpp_smart_strings) )
 			// ensure utf8 chars are not cut
 			else if( c >= 0x80 ) {
 				pos++;

+ 1 - 1
std/haxe/xml/Parser.hx

@@ -378,7 +378,7 @@ class Parser
 							var c = s.fastCodeAt(1) == 'x'.code
 								? Std.parseInt("0" +s.substr(1, s.length - 1))
 								: Std.parseInt(s.substr(1, s.length - 1));
-							#if (neko || cpp || php || lua || eval)
+							#if (neko || (cpp && !hxcpp_smart_strings) || php || lua || eval)
 							if( c >= 128 ) {
 								// UTF8-encode it
 								if( c <= 0x7FF ) {