Skip to content

Commit 52566c9

Browse files
committed
Rearrange tests; improve RandomBigInteger to also generate from hex strings; fix a potential bug in fromRadixSubstring
1 parent ee27ae4 commit 52566c9

File tree

9 files changed

+1322
-1310
lines changed

9 files changed

+1322
-1310
lines changed

src/main/java/com/upokecenter/cbor/CBORJson.java

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,17 @@ static String NextJSONString(CharacterReader reader, int quote) {
8080
c <<= 4;
8181
c |= ch + 10 - 'a';
8282
} else {
83-
throw reader.NewError("Invalid Unicode escaped character");
83+
throw
84+
reader.NewError("Invalid Unicode escaped character"
85+
);
8486
}
8587
}
8688
break;
8789
}
88-
default: throw reader.NewError("Invalid escaped character");
90+
default: throw reader.NewError("Invalid escaped character");
8991
}
9092
break;
91-
default: escaped = false;
93+
default: escaped = false;
9294
break;
9395
}
9496
if (surrogate) {
@@ -278,18 +280,18 @@ static CBORObject ParseJSONObject(
278280
}
279281
// NOTE: Will overwrite existing value
280282
myHashMap.put(key, NextJSONValue(
281-
reader,
283+
reader,
282284
SkipWhitespaceJSON(reader),
283-
noDuplicates,
284-
nextchar,
285-
depth));
285+
noDuplicates,
286+
nextchar,
287+
depth));
286288
switch (nextchar[0]) {
287289
case ',':
288290
seenComma = true;
289291
break;
290292
case '}':
291293
return CBORObject.FromRaw(myHashMap);
292-
default: throw reader.NewError("Expected a ',' or '}'");
294+
default: throw reader.NewError("Expected a ',' or '}'");
293295
}
294296
}
295297
}
@@ -320,11 +322,11 @@ static CBORObject ParseJSONArray(
320322
}
321323
myArrayList.add(
322324
NextJSONValue(
323-
reader,
324-
c,
325-
noDuplicates,
326-
nextchar,
327-
depth));
325+
reader,
326+
c,
327+
noDuplicates,
328+
nextchar,
329+
depth));
328330
c = nextchar[0];
329331
switch (c) {
330332
case ',':
@@ -357,8 +359,8 @@ static void WriteJSONStringUnquoted(
357359
sb.WriteChar('\\');
358360
sb.WriteChar(c);
359361
} else if (c < 0x20 || (c >= 0x85 && (c == 0x2028 || c == 0x2029 ||
360-
c == 0x85 || c == 0xfeff || c == 0xfffe ||
361-
c == 0xffff))) {
362+
c == 0x85 || c == 0xfeff || c == 0xfffe ||
363+
c == 0xffff))) {
362364
// Control characters, and also the line and paragraph separators
363365
// which apparently can't appear in JavaScript (as opposed to
364366
// JSON) strings
@@ -430,7 +432,7 @@ static void WriteJSONToInternal(
430432
}
431433
writer.WriteString(
432434
CBORObject.TrimDotZero(
433-
Float.toString((float)f)));
435+
Float.toString((float)f)));
434436
return;
435437
}
436438
case CBORObject.CBORObjectTypeDouble: {
@@ -441,7 +443,7 @@ static void WriteJSONToInternal(
441443
return;
442444
}
443445
writer.WriteString(CBORObject.TrimDotZero(
444-
Double.toString((double)f)));
446+
Double.toString((double)f)));
445447
return;
446448
}
447449
case CBORObject.CBORObjectTypeInteger: {
@@ -450,7 +452,8 @@ static void WriteJSONToInternal(
450452
return;
451453
}
452454
case CBORObject.CBORObjectTypeBigInteger: {
453-
writer.WriteString(CBORUtilities.BigIntToString((BigInteger)thisItem));
455+
writer.WriteString(
456+
CBORUtilities.BigIntToString((BigInteger)thisItem));
454457
return;
455458
}
456459
case CBORObject.CBORObjectTypeExtendedDecimal: {
@@ -475,13 +478,13 @@ static void WriteJSONToInternal(
475478
// so convert to double instead
476479
double f = flo.ToDouble();
477480
if (((f) == Double.NEGATIVE_INFINITY) ||
478-
((f) == Double.POSITIVE_INFINITY) || Double.isNaN(f)) {
481+
((f) == Double.POSITIVE_INFINITY) || Double.isNaN(f)) {
479482
writer.WriteString("null");
480483
return;
481484
}
482485
writer.WriteString(
483486
CBORObject.TrimDotZero(
484-
Double.toString((double)f)));
487+
Double.toString((double)f)));
485488
return;
486489
}
487490
writer.WriteString(flo.toString());
@@ -497,11 +500,11 @@ static void WriteJSONToInternal(
497500
writer.WriteChar('\"');
498501
if (obj.HasTag(22)) {
499502
Base64.WriteBase64(
500-
writer,
501-
byteArray,
502-
0,
503-
byteArray.length,
504-
false);
503+
writer,
504+
byteArray,
505+
0,
506+
byteArray.length,
507+
false);
505508
} else if (obj.HasTag(23)) {
506509
// Write as base16
507510
for (int i = 0; i < byteArray.length; ++i) {
@@ -510,11 +513,11 @@ static void WriteJSONToInternal(
510513
}
511514
} else {
512515
Base64.WriteBase64URL(
513-
writer,
514-
byteArray,
515-
0,
516-
byteArray.length,
517-
false);
516+
writer,
517+
byteArray,
518+
0,
519+
byteArray.length,
520+
false);
518521
}
519522
writer.WriteChar('\"');
520523
break;
@@ -591,7 +594,8 @@ static void WriteJSONToInternal(
591594
for (Map.Entry<CBORObject, CBORObject> entry : objMap.entrySet()) {
592595
CBORObject key = entry.getKey();
593596
CBORObject value = entry.getValue();
594-
String str = (key.getItemType() == CBORObject.CBORObjectTypeTextString) ?
597+
String str = (key.getItemType() ==
598+
CBORObject.CBORObjectTypeTextString) ?
595599
((String)key.getThisItem()) : key.ToJSONString();
596600
stringMap.put(str, value);
597601
}

0 commit comments

Comments
 (0)