@@ -17,8 +17,8 @@ static void WriteJSONStringUnquoted(
1717 for (; i < str .length (); ++i ) {
1818 char c = str .charAt (i );
1919 if (c < 0x20 || c >= 0x7f || c == '\\' || c == '"' ) {
20- sb .WriteString (str , 0 , i );
21- break ;
20+ sb .WriteString (str , 0 , i );
21+ break ;
2222 }
2323 }
2424 if (i == str .length ()) {
@@ -60,39 +60,39 @@ static void WriteJSONStringUnquoted(
6060 sb .WriteCodePoint ((int )Hex16 .charAt ((int )(c & 15 )));
6161 }
6262 } else if ((c & 0xfc00 ) == 0xd800 ) {
63- if (i >= str .length () - 1 || (str .charAt (i + 1 ) & 0xfc00 ) != 0xdc00 ) {
64- // NOTE: RFC 8259 doesn't prohibit any particular
65- // error-handling behavior when a writer of JSON
66- // receives a String with an unpaired surrogate.
67- if (options .getReplaceSurrogates ()) {
68- // Replace unpaired surrogate with U+FFFD
69- sb .WriteCodePoint (0xfffd );
70- } else {
71- throw new CBORException ("Unpaired surrogate in String" );
72- }
73- } else if (c >= 0x80 && options .getWriteBasic ()) {
74- c = str .charAt (i );
75- sb .WriteString ("\\ u" );
76- sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 12 ) & 15 )));
77- sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 8 ) & 15 )));
78- sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 4 ) & 15 )));
79- sb .WriteCodePoint ((int )Hex16 .charAt ((int )(c & 15 )));
80- c = str .charAt (i + 1 );
81- sb .WriteString ("\\ u" );
82- sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 12 ) & 15 )));
83- sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 8 ) & 15 )));
84- sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 4 ) & 15 )));
85- sb .WriteCodePoint ((int )Hex16 .charAt ((int )(c & 15 )));
63+ if (i >= str .length () - 1 || (str .charAt (i + 1 ) & 0xfc00 ) != 0xdc00 ) {
64+ // NOTE: RFC 8259 doesn't prohibit any particular
65+ // error-handling behavior when a writer of JSON
66+ // receives a String with an unpaired surrogate.
67+ if (options .getReplaceSurrogates ()) {
68+ // Replace unpaired surrogate with U+FFFD
69+ sb .WriteCodePoint (0xfffd );
8670 } else {
87- sb . WriteString ( str , i , 2 );
71+ throw new CBORException ( "Unpaired surrogate in String" );
8872 }
89- ++ i ;
90- } else if ( c >= 0x80 && options . getWriteBasic ()) {
73+ } else if ( c >= 0x80 && options . getWriteBasic ()) {
74+ c = str . charAt ( i );
9175 sb .WriteString ("\\ u" );
9276 sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 12 ) & 15 )));
9377 sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 8 ) & 15 )));
9478 sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 4 ) & 15 )));
9579 sb .WriteCodePoint ((int )Hex16 .charAt ((int )(c & 15 )));
80+ c = str .charAt (i + 1 );
81+ sb .WriteString ("\\ u" );
82+ sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 12 ) & 15 )));
83+ sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 8 ) & 15 )));
84+ sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 4 ) & 15 )));
85+ sb .WriteCodePoint ((int )Hex16 .charAt ((int )(c & 15 )));
86+ } else {
87+ sb .WriteString (str , i , 2 );
88+ }
89+ ++i ;
90+ } else if (c >= 0x80 && options .getWriteBasic ()) {
91+ sb .WriteString ("\\ u" );
92+ sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 12 ) & 15 )));
93+ sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 8 ) & 15 )));
94+ sb .WriteCodePoint ((int )Hex16 .charAt ((int )((c >> 4 ) & 15 )));
95+ sb .WriteCodePoint ((int )Hex16 .charAt ((int )(c & 15 )));
9696 } else {
9797 sb .WriteCodePoint ((int )c );
9898 }
@@ -112,8 +112,8 @@ static void WriteJSONToInternal(
112112 }
113113
114114 private static void PopRefIfNeeded (
115- List <CBORObject > stack ,
116- boolean pop ) {
115+ List <CBORObject > stack ,
116+ boolean pop ) {
117117 if (pop && stack != null ) {
118118 stack .remove (stack .size () - 1 );
119119 }
0 commit comments