Skip to content

Commit d21da52

Browse files
committed
update Java version
1 parent 9c3aa99 commit d21da52

File tree

5 files changed

+384
-141
lines changed

5 files changed

+384
-141
lines changed

api/com.upokecenter.cbor.CBORObject.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4294,9 +4294,9 @@ Gets the CBOR object referred to by a JSON Pointer according to RFC6901. For
42944294

42954295
* <code>CBORException</code> - Thrown if the pointer is null, or
42964296
if the pointer is invalid, or if there is no object at the given
4297-
pointer, or the special key "-" appears in the pointer, or if the
4298-
pointer is non-empty and this object has a CBOR type other than
4299-
array or map.
4297+
pointer, or the special key "-" appears in the pointer in the
4298+
context of an array (not a map), or if the pointer is non-empty and
4299+
this object has a CBOR type other than array or map.
43004300

43014301
### <a id='AtJSONPointer(java.lang.String,com.upokecenter.cbor.CBORObject)'>AtJSONPointer</a>
43024302
'/' KEY '/' KEY.get(...)
@@ -4329,8 +4329,8 @@ Gets the CBOR object referred to by a JSON Pointer according to RFC6901, or
43294329
other than array or map). Returns <code>defaultValue</code> if the
43304330
pointer is null, or if the pointer is invalid, or if there is no
43314331
object at the given pointer, or the special key "-" appears in the
4332-
pointer, or if the pointer is non-empty and this object has a CBOR
4333-
type other than array or map.
4332+
pointer in the context of an array (not a map), or if the pointer is
4333+
non-empty and this object has a CBOR type other than array or map.
43344334

43354335
### <a id='ApplyJSONPatch(com.upokecenter.cbor.CBORObject)'>ApplyJSONPatch</a>
43364336

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5209,9 +5209,9 @@ public byte[] EncodeToBytes(CBOREncodeOptions options) {
52095209
* array or map).
52105210
* @throws com.upokecenter.cbor.CBORException Thrown if the pointer is null, or
52115211
* if the pointer is invalid, or if there is no object at the given
5212-
* pointer, or the special key "-" appears in the pointer, or if the
5213-
* pointer is non-empty and this object has a CBOR type other than
5214-
* array or map.
5212+
* pointer, or the special key "-" appears in the pointer in the
5213+
* context of an array (not a map), or if the pointer is non-empty and
5214+
* this object has a CBOR type other than array or map.
52155215
*/
52165216
public CBORObject AtJSONPointer(String pointer) {
52175217
CBORObject ret = this.AtJSONPointer(pointer, null);
@@ -5244,8 +5244,8 @@ public CBORObject AtJSONPointer(String pointer) {
52445244
* other than array or map). Returns {@code defaultValue} if the
52455245
* pointer is null, or if the pointer is invalid, or if there is no
52465246
* object at the given pointer, or the special key "-" appears in the
5247-
* pointer, or if the pointer is non-empty and this object has a CBOR
5248-
* type other than array or map.
5247+
* pointer in the context of an array (not a map), or if the pointer is
5248+
* non-empty and this object has a CBOR type other than array or map.
52495249
*/
52505250
public CBORObject AtJSONPointer(String pointer, CBORObject defaultValue) {
52515251
return JSONPointer.GetObject(this, pointer, null);

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ licensed under Creative Commons Zero (CC0):
1313
import com.upokecenter.numbers.*;
1414

1515
final class JSONPointer {
16+
private final String refValue;
17+
private final boolean isRoot;
18+
private final CBORObject jsonobj;
19+
1620
public static JSONPointer FromPointer(CBORObject obj, String pointer) {
1721
int index = 0;
1822
if (pointer == null) {
@@ -22,7 +26,7 @@ public static JSONPointer FromPointer(CBORObject obj, String pointer) {
2226
throw new NullPointerException("obj");
2327
}
2428
if (pointer.length() == 0) {
25-
return new JSONPointer(obj, pointer);
29+
return new JSONPointer(obj, pointer, true);
2630
}
2731
while (true) {
2832
if (obj == null) {
@@ -199,11 +203,12 @@ private static int ReadPositiveInteger(
199203
return index;
200204
}
201205

202-
private String refValue;
203-
204-
private CBORObject jsonobj;
205-
206206
private JSONPointer(CBORObject jsonobj, String refValue) {
207+
this(jsonobj, refValue, false);
208+
}
209+
210+
private JSONPointer(CBORObject jsonobj, String refValue, boolean isRoot) {
211+
this.isRoot = isRoot;
207212
this.jsonobj = jsonobj;
208213
this.refValue = refValue;
209214
}
@@ -259,7 +264,7 @@ public CBORObject GetParent() {
259264
}
260265

261266
public CBORObject GetValue() {
262-
if (this.refValue.length() == 0) {
267+
if (this.isRoot) {
263268
// Root always exists
264269
return this.jsonobj;
265270
}

0 commit comments

Comments
 (0)