Skip to content

Commit f47e0a6

Browse files
committed
Style changes
1 parent b7cd29b commit f47e0a6

31 files changed

+4865
-6653
lines changed

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

Lines changed: 48 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,48 +24,48 @@ public static void ToBase64(StringBuilder str, byte[] data, boolean padding) {
2424
}
2525

2626
public static void ToBase64URL(
27-
StringBuilder str,
28-
byte[] data,
29-
boolean padding) {
27+
StringBuilder str,
28+
byte[] data,
29+
boolean padding) {
3030
if (data == null) {
3131
throw new NullPointerException("data");
3232
}
3333
ToBase64(str, data, 0, data.length, Base64URL, padding);
3434
}
3535

3636
public static void ToBase64(
37-
StringBuilder str,
38-
byte[] data,
39-
int offset,
40-
int count,
41-
boolean padding) {
37+
StringBuilder str,
38+
byte[] data,
39+
int offset,
40+
int count,
41+
boolean padding) {
4242
ToBase64(str, data, offset, count, Base64Classic, padding);
4343
}
4444

4545
public static void ToBase64URL(
46-
StringBuilder str,
47-
byte[] data,
48-
int offset,
49-
int count,
50-
boolean padding) {
46+
StringBuilder str,
47+
byte[] data,
48+
int offset,
49+
int count,
50+
boolean padding) {
5151
ToBase64(str, data, offset, count, Base64URL, padding);
5252
}
5353

5454
public static void WriteBase64(
55-
StringOutput writer,
56-
byte[] data,
57-
int offset,
58-
int count,
59-
boolean padding) throws java.io.IOException {
55+
StringOutput writer,
56+
byte[] data,
57+
int offset,
58+
int count,
59+
boolean padding) throws java.io.IOException {
6060
WriteBase64(writer, data, offset, count, Base64Classic, padding);
6161
}
6262

6363
public static void WriteBase64URL(
64-
StringOutput writer,
65-
byte[] data,
66-
int offset,
67-
int count,
68-
boolean padding) throws java.io.IOException {
64+
StringOutput writer,
65+
byte[] data,
66+
int offset,
67+
int count,
68+
boolean padding) throws java.io.IOException {
6969
WriteBase64(writer, data, offset, count, Base64URL, padding);
7070
}
7171

@@ -84,32 +84,32 @@ public static String ToBase64URLString(byte[] data, boolean padding) {
8484
}
8585

8686
public static String ToBase64String(
87-
byte[] data,
88-
int offset,
89-
int count,
90-
boolean padding) {
87+
byte[] data,
88+
int offset,
89+
int count,
90+
boolean padding) {
9191
StringBuilder builder = new StringBuilder();
9292
ToBase64(builder, data, offset, count, Base64Classic, padding);
9393
return builder.toString();
9494
}
9595

9696
public static String ToBase64URLString(
97-
byte[] data,
98-
int offset,
99-
int count,
100-
boolean padding) {
97+
byte[] data,
98+
int offset,
99+
int count,
100+
boolean padding) {
101101
StringBuilder builder = new StringBuilder();
102102
ToBase64(builder, data, offset, count, Base64Classic, padding);
103103
return builder.toString();
104104
}
105105

106106
private static void ToBase64(
107-
StringBuilder str,
108-
byte[] data,
109-
int offset,
110-
int count,
111-
String alphabet,
112-
boolean padding) {
107+
StringBuilder str,
108+
byte[] data,
109+
int offset,
110+
int count,
111+
String alphabet,
112+
boolean padding) {
113113
if (str == null) {
114114
throw new NullPointerException("str");
115115
}
@@ -134,8 +134,7 @@ private static void ToBase64(
134134
}
135135
if (data.length - offset < count) {
136136
throw new IllegalArgumentException("data's length minus " + offset + " (" +
137-
(data.length - offset) +
138-
") is less than " + count);
137+
(data.length - offset) + ") is less than " + count);
139138
}
140139
int length = offset + count;
141140
int i = offset;
@@ -167,12 +166,12 @@ private static void ToBase64(
167166
}
168167

169168
private static void WriteBase64(
170-
StringOutput writer,
171-
byte[] data,
172-
int offset,
173-
int count,
174-
String alphabet,
175-
boolean padding) throws java.io.IOException {
169+
StringOutput writer,
170+
byte[] data,
171+
int offset,
172+
int count,
173+
String alphabet,
174+
boolean padding) throws java.io.IOException {
176175
if (writer == null) {
177176
throw new NullPointerException("writer");
178177
}
@@ -194,20 +193,17 @@ private static void WriteBase64(
194193
}
195194
if (data.length - offset < count) {
196195
throw new IllegalArgumentException("data's length minus " + offset + " (" +
197-
(data.length - offset) +
198-
") is less than " + count);
196+
(data.length - offset) + ") is less than " + count);
199197
}
200198
int length = offset + count;
201199
int i = offset;
202200
char[] buffer = new char[4];
203201
for (i = offset; i < (length - 2); i += 3) {
204202
buffer[0] = (char)alphabet.charAt((data[i] >> 2) & 63);
205203
buffer[1] = (char)alphabet.charAt(((data[i] & 3) << 4) +
206-
((data[i + 1] >> 4) &
207-
15));
204+
((data[i + 1] >> 4) & 15));
208205
buffer[2] = (char)alphabet.charAt(((data[i + 1] & 15) << 2) + ((data[i +
209-
2] >> 6) &
210-
3));
206+
2] >> 6) & 3));
211207
buffer[3] = (char)alphabet.charAt(data[i + 2] & 63);
212208
writer.WriteChar(buffer[0]);
213209
writer.WriteChar(buffer[1]);
@@ -220,8 +216,7 @@ private static void WriteBase64(
220216
buffer[0] = (char)alphabet.charAt((data[i] >> 2) & 63);
221217
if (lenmod3 == 2) {
222218
buffer[1] = (char)alphabet.charAt(((data[i] & 3) << 4) + ((data[i + 1] >>
223-
4) &
224-
15));
219+
4) & 15));
225220
buffer[2] = (char)alphabet.charAt((data[i + 1] & 15) << 2);
226221
writer.WriteChar(buffer[0]);
227222
writer.WriteChar(buffer[1]);

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

Lines changed: 37 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,15 @@ static String NextJSONString(CharacterReader reader, int quote) {
8080
c <<= 4;
8181
c |= ch + 10 - 'a';
8282
} else {
83-
throw
84-
reader.NewError(
85-
"Invalid Unicode escaped character");
83+
throw reader.NewError("Invalid Unicode escaped character");
8684
}
8785
}
8886
break;
8987
}
90-
default:
91-
throw reader.NewError("Invalid escaped character");
88+
default: throw reader.NewError("Invalid escaped character");
9289
}
9390
break;
94-
default:
95-
escaped = false;
91+
default: escaped = false;
9692
break;
9793
}
9894
if (surrogate) {
@@ -161,8 +157,7 @@ static CBORObject NextJSONValue(
161157
}
162158
if (c == 't') {
163159
// Parse true
164-
if (reader.NextChar() != 'r' ||
165-
reader.NextChar() != 'u' ||
160+
if (reader.NextChar() != 'r' || reader.NextChar() != 'u' ||
166161
reader.NextChar() != 'e') {
167162
throw reader.NewError("Value can't be parsed.");
168163
}
@@ -171,19 +166,16 @@ static CBORObject NextJSONValue(
171166
}
172167
if (c == 'f') {
173168
// Parse false
174-
if (reader.NextChar() != 'a' ||
175-
reader.NextChar() != 'l' ||
176-
reader.NextChar() != 's' ||
177-
reader.NextChar() != 'e') {
169+
if (reader.NextChar() != 'a' || reader.NextChar() != 'l' ||
170+
reader.NextChar() != 's' || reader.NextChar() != 'e') {
178171
throw reader.NewError("Value can't be parsed.");
179172
}
180173
nextChar[0] = SkipWhitespaceJSON(reader);
181174
return CBORObject.False;
182175
}
183176
if (c == 'n') {
184177
// Parse null
185-
if (reader.NextChar() != 'u' ||
186-
reader.NextChar() != 'l' ||
178+
if (reader.NextChar() != 'u' || reader.NextChar() != 'l' ||
187179
reader.NextChar() != 'l') {
188180
throw reader.NewError("Value can't be parsed.");
189181
}
@@ -286,19 +278,18 @@ static CBORObject ParseJSONObject(
286278
}
287279
// NOTE: Will overwrite existing value
288280
myHashMap.put(key, NextJSONValue(
289-
reader,
281+
reader,
290282
SkipWhitespaceJSON(reader),
291-
noDuplicates,
292-
nextchar,
293-
depth));
283+
noDuplicates,
284+
nextchar,
285+
depth));
294286
switch (nextchar[0]) {
295287
case ',':
296288
seenComma = true;
297289
break;
298290
case '}':
299291
return CBORObject.FromRaw(myHashMap);
300-
default:
301-
throw reader.NewError("Expected a ',' or '}'");
292+
default: throw reader.NewError("Expected a ',' or '}'");
302293
}
303294
}
304295
}
@@ -329,11 +320,11 @@ static CBORObject ParseJSONArray(
329320
}
330321
myArrayList.add(
331322
NextJSONValue(
332-
reader,
333-
c,
334-
noDuplicates,
335-
nextchar,
336-
depth));
323+
reader,
324+
c,
325+
noDuplicates,
326+
nextchar,
327+
depth));
337328
c = nextchar[0];
338329
switch (c) {
339330
case ',':
@@ -366,8 +357,7 @@ static void WriteJSONStringUnquoted(
366357
sb.WriteChar('\\');
367358
sb.WriteChar(c);
368359
} else if (c < 0x20 || (c >= 0x85 && (c == 0x2028 || c == 0x2029 ||
369-
c == 0x85 || c == 0xfeff || c == 0xfffe ||
370-
360+
c == 0x85 || c == 0xfeff || c == 0xfffe ||
371361
c == 0xffff))) {
372362
// Control characters, and also the line and paragraph separators
373363
// which apparently can't appear in JavaScript (as opposed to
@@ -434,38 +424,33 @@ static void WriteJSONToInternal(
434424
case CBORObject.CBORObjectTypeSingle: {
435425
float f = ((Float)thisItem).floatValue();
436426
if (((f) == Float.NEGATIVE_INFINITY) ||
437-
((f) == Float.POSITIVE_INFINITY) ||
438-
Float.isNaN(f)) {
427+
((f) == Float.POSITIVE_INFINITY) || Float.isNaN(f)) {
439428
writer.WriteString("null");
440429
return;
441430
}
442431
writer.WriteString(
443432
CBORObject.TrimDotZero(
444-
Float.toString((float)f)));
433+
Float.toString((float)f)));
445434
return;
446435
}
447436
case CBORObject.CBORObjectTypeDouble: {
448437
double f = ((Double)thisItem).doubleValue();
449-
if (((f) == Double.NEGATIVE_INFINITY) ||
450-
((f) == Double.POSITIVE_INFINITY) ||
438+
if (((f) == Double.NEGATIVE_INFINITY) || ((f) == Double.POSITIVE_INFINITY) ||
451439
Double.isNaN(f)) {
452440
writer.WriteString("null");
453441
return;
454442
}
455-
writer.WriteString(
456-
CBORObject.TrimDotZero(
443+
writer.WriteString(CBORObject.TrimDotZero(
457444
Double.toString((double)f)));
458445
return;
459446
}
460447
case CBORObject.CBORObjectTypeInteger: {
461448
long longItem = (((Long)thisItem).longValue());
462-
writer.WriteString(
463-
CBORUtilities.LongToString(longItem));
449+
writer.WriteString(CBORUtilities.LongToString(longItem));
464450
return;
465451
}
466452
case CBORObject.CBORObjectTypeBigInteger: {
467-
writer.WriteString(
468-
CBORUtilities.BigIntToString((BigInteger)thisItem));
453+
writer.WriteString(CBORUtilities.BigIntToString((BigInteger)thisItem));
469454
return;
470455
}
471456
case CBORObject.CBORObjectTypeExtendedDecimal: {
@@ -490,14 +475,13 @@ static void WriteJSONToInternal(
490475
// so convert to double instead
491476
double f = flo.ToDouble();
492477
if (((f) == Double.NEGATIVE_INFINITY) ||
493-
((f) == Double.POSITIVE_INFINITY) ||
494-
Double.isNaN(f)) {
478+
((f) == Double.POSITIVE_INFINITY) || Double.isNaN(f)) {
495479
writer.WriteString("null");
496480
return;
497481
}
498482
writer.WriteString(
499483
CBORObject.TrimDotZero(
500-
Double.toString((double)f)));
484+
Double.toString((double)f)));
501485
return;
502486
}
503487
writer.WriteString(flo.toString());
@@ -513,11 +497,11 @@ static void WriteJSONToInternal(
513497
writer.WriteChar('\"');
514498
if (obj.HasTag(22)) {
515499
Base64.WriteBase64(
516-
writer,
517-
byteArray,
518-
0,
519-
byteArray.length,
520-
false);
500+
writer,
501+
byteArray,
502+
0,
503+
byteArray.length,
504+
false);
521505
} else if (obj.HasTag(23)) {
522506
// Write as base16
523507
for (int i = 0; i < byteArray.length; ++i) {
@@ -526,11 +510,11 @@ static void WriteJSONToInternal(
526510
}
527511
} else {
528512
Base64.WriteBase64URL(
529-
writer,
530-
byteArray,
531-
0,
532-
byteArray.length,
533-
false);
513+
writer,
514+
byteArray,
515+
0,
516+
byteArray.length,
517+
false);
534518
}
535519
writer.WriteChar('\"');
536520
break;
@@ -607,8 +591,7 @@ static void WriteJSONToInternal(
607591
for (Map.Entry<CBORObject, CBORObject> entry : objMap.entrySet()) {
608592
CBORObject key = entry.getKey();
609593
CBORObject value = entry.getValue();
610-
String str = (key.getItemType() ==
611-
CBORObject.CBORObjectTypeTextString) ?
594+
String str = (key.getItemType() == CBORObject.CBORObjectTypeTextString) ?
612595
((String)key.getThisItem()) : key.ToJSONString();
613596
stringMap.put(str, value);
614597
}

0 commit comments

Comments
 (0)