@@ -153,7 +153,7 @@ public final class CharTypes
153
153
* Lookup table used for determining which output characters in
154
154
* 7-bit ASCII range need to be quoted.
155
155
*/
156
- protected final static int [] sOutputEscapes128 ;
156
+ protected final static int [] sOutputEscapes128NoSlash ;
157
157
static {
158
158
int [] table = new int [128 ];
159
159
// Control chars need generic escape sequence
@@ -170,16 +170,16 @@ public final class CharTypes
170
170
table [0x0C ] = 'f' ;
171
171
table [0x0A ] = 'n' ;
172
172
table [0x0D ] = 'r' ;
173
- sOutputEscapes128 = table ;
173
+ sOutputEscapes128NoSlash = table ;
174
174
}
175
175
176
176
/**
177
- * Lookup table same as {@link #sOutputEscapes128 } except that
177
+ * Lookup table same as {@link #sOutputEscapes128NoSlash } except that
178
178
* forward slash ('/') is also escaped
179
179
*/
180
180
protected final static int [] sOutputEscapes128WithSlash ;
181
181
static {
182
- sOutputEscapes128WithSlash = Arrays .copyOf (sOutputEscapes128 , sOutputEscapes128 .length );
182
+ sOutputEscapes128WithSlash = Arrays .copyOf (sOutputEscapes128NoSlash , sOutputEscapes128NoSlash .length );
183
183
sOutputEscapes128WithSlash ['/' ] = '/' ;
184
184
}
185
185
@@ -220,23 +220,7 @@ public final class CharTypes
220
220
*
221
221
* @return 128-entry {@code int[]} that contains escape definitions
222
222
*/
223
- public static int [] get7BitOutputEscapes () { return sOutputEscapes128 ; }
224
-
225
- /**
226
- * Alternative to {@link #get7BitOutputEscapes()} when a non-standard quote character
227
- * is used.
228
- *
229
- * @param quoteChar Character used for quoting textual values and property names;
230
- * usually double-quote but sometimes changed to single-quote (apostrophe)
231
- *
232
- * @return 128-entry {@code int[]} that contains escape definitions
233
- */
234
- public static int [] get7BitOutputEscapes (int quoteChar ) {
235
- if (quoteChar == '"' ) {
236
- return sOutputEscapes128 ;
237
- }
238
- return AltEscapes .instance .escapesFor (quoteChar );
239
- }
223
+ public static int [] get7BitOutputEscapes () { return sOutputEscapes128WithSlash ; }
240
224
241
225
/**
242
226
* Alternative to {@link #get7BitOutputEscapes()} when either a non-standard
@@ -255,7 +239,7 @@ public static int[] get7BitOutputEscapes(int quoteChar, boolean escapeSlash) {
255
239
if (escapeSlash ) {
256
240
return sOutputEscapes128WithSlash ;
257
241
}
258
- return sOutputEscapes128 ;
242
+ return sOutputEscapes128NoSlash ;
259
243
}
260
244
return AltEscapes .instance .escapesFor (quoteChar , escapeSlash );
261
245
}
@@ -283,7 +267,7 @@ public static char hexToChar(int ch)
283
267
* @param content Unescaped String value to append with escaping applied
284
268
*/
285
269
public static void appendQuoted (StringBuilder sb , String content ) {
286
- final int [] escCodes = sOutputEscapes128 ;
270
+ final int [] escCodes = sOutputEscapes128WithSlash ;
287
271
final int escLen = escCodes .length ;
288
272
for (int i = 0 , len = content .length (); i < len ; ++i ) {
289
273
char c = content .charAt (i );
@@ -330,35 +314,27 @@ public static byte[] copyHexBytes(boolean uppercase) {
330
314
private static class AltEscapes {
331
315
public final static AltEscapes instance = new AltEscapes ();
332
316
333
- private int [][] _altEscapes = new int [128 ][];
317
+ private int [][] _altEscapesNoSlash = new int [128 ][];
334
318
335
319
// @since 2.17
336
320
private int [][] _altEscapesWithSlash = new int [128 ][];
337
321
338
- public int [] escapesFor (int quoteChar ) {
339
- int [] esc = _altEscapes [quoteChar ];
340
- if (esc == null ) {
341
- esc = Arrays .copyOf (sOutputEscapes128 , 128 );
342
- // Only add escape setting if character does not already have it
343
- if (esc [quoteChar ] == 0 ) {
344
- esc [quoteChar ] = CharacterEscapes .ESCAPE_STANDARD ;
345
- }
346
- _altEscapes [quoteChar ] = esc ;
347
- }
348
- return esc ;
349
- }
350
-
351
- // @since 2.17
352
322
public int [] escapesFor (int quoteChar , boolean escapeSlash )
353
323
{
354
- if (!escapeSlash ) {
355
- return escapesFor (quoteChar );
356
- }
357
- int [] esc = _altEscapesWithSlash [quoteChar ];
324
+ int [] esc = escapeSlash
325
+ ? _altEscapesWithSlash [quoteChar ]
326
+ : _altEscapesNoSlash [quoteChar ];
358
327
if (esc == null ) {
359
- esc = escapesFor (quoteChar );
360
- esc ['/' ] = '/' ;
328
+ esc = escapeSlash
329
+ ? sOutputEscapes128WithSlash
330
+ : sOutputEscapes128NoSlash ;
331
+ esc = Arrays .copyOf (esc , esc .length );
361
332
_altEscapesWithSlash [quoteChar ] = esc ;
333
+ if (escapeSlash ) {
334
+ _altEscapesWithSlash [quoteChar ] = esc ;
335
+ } else {
336
+ _altEscapesNoSlash [quoteChar ] = esc ;
337
+ }
362
338
}
363
339
return esc ;
364
340
}
0 commit comments