Skip to content

Commit 58b02a5

Browse files
committed
0.2.0 - Remove JsonLiteArray.stringifyArray() and improved unit tests.
1 parent 39194f7 commit 58b02a5

File tree

11 files changed

+133
-71
lines changed

11 files changed

+133
-71
lines changed

.classpath

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
<classpath>
33
<classpathentry kind="src" path="src"/>
44
<classpathentry kind="src" path="test"/>
5-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
6-
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jarray-util/bin/jarray_util.jar" sourcepath="/JArrayUtil"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
6+
<attributes>
7+
<attribute name="module" value="true"/>
8+
</attributes>
9+
</classpathentry>
10+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
11+
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/TestChecks"/>
12+
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jarrays/bin/jarrays.jar" sourcepath="/JArrayUtil"/>
713
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jfunc/bin/jfunc.jar" sourcepath="/JFunc"/>
814
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jprimitive-collections/bin/jprimitive_collections.jar" sourcepath="/JPrimitiveCollections"/>
915
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jrange/bin/jrange.jar" sourcepath="/JRange"/>
1016
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jstreamish/bin/jstreamish.jar" sourcepath="/JStreamish"/>
1117
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jtext-parser/bin/jtext_parser.jar" sourcepath="/JTextParser"/>
1218
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/jtext-util/bin/jtext_util.jar" sourcepath="/JTextUtil"/>
13-
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
14-
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/TestChecks"/>
1519
<classpathentry kind="output" path="bin"/>
1620
</classpath>

CHANGELOG.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/
44

55

66
--------
7-
###[0.1.2](N/A) - 2016-09-11
7+
### [0.2.0](N/A) - 2020-05-09
8+
#### Removed
9+
* `JsonLiteArray.stringifyArray()` since it was unused and same behavior available from `JsonStringify` library
10+
11+
12+
--------
13+
### [0.1.2](https://github.com/TeamworkGuy2/JParseJsonLite/commit/39194f7ebfa14dc67dae6c0ef5aea6b27bbad935) - 2016-09-11
814
#### Changed
9-
* Updated jtext-parser dependency to latest 0.9.0 version (TextParserImpl -> TextIteratorParser)
15+
* Updated `jtext-parser` dependency to latest `0.9.0` version (`TextParserImpl` -> `TextIteratorParser`)
1016

1117

1218
--------
13-
###[0.1.1](https://github.com/TeamworkGuy2/JParseJsonLite/commit/d366c341b32743dc47102f4c1c5b55a0cca79f0e) - 2016-09-02
19+
### [0.1.1](https://github.com/TeamworkGuy2/JParseJsonLite/commit/d366c341b32743dc47102f4c1c5b55a0cca79f0e) - 2016-09-02
1420
#### Changed
15-
* Renamed repository from JParserJsonLite -> JParseJsonLite
21+
* Renamed repository from `JParserJsonLite` -> `JParseJsonLite`
1622

1723

1824
--------
19-
###[0.1.0](https://github.com/TeamworkGuy2/JParseJsonLite/commit/6c02195791eb08fb5031ce489d153971b4401f15) - 2016-09-01
25+
### [0.1.0](https://github.com/TeamworkGuy2/JParseJsonLite/commit/6c02195791eb08fb5031ce489d153971b4401f15) - 2016-09-01
2026
Includes simple JSON parsing code from [JParserDataTypeLike](https://github.com/TeamworkGuy2/JParserDataTypeLike) which came from [JLikelyParser](https://github.com/TeamworkGuy2/JLikelyParser).
2127
* twg2.parser.jsonLite - for parsing JSON like arrays, strings, and numbers

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
JParseJsonLite
22
==============
3-
version: 0.1.2
43

5-
####twg2.parser.jsonLite
4+
#### twg2.parser.jsonLite
65
for parsing JSON like arrays, numbers, and strings, as well as arrays with none quoted strings.
7-
'JSON like' meaning it supports most common JSON syntax or a superset (such as unquoted property names), but may not support the [JSON spec](http://json.org/)
6+
'JSON like' meaning it supports common JSON syntax and common extensions such as unquoted property names, but may not fully support the [JSON spec](http://json.org/)
1.47 KB
Binary file not shown.

bin/jparse_json_lite.jar

-280 Bytes
Binary file not shown.

package-lib.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version" : "0.1.2",
2+
"version" : "0.2.0",
33
"name" : "jparse-json-lite",
44
"description" : "Simple parsing for JSON strings/files",
55
"homepage" : "https://github.com/TeamworkGuy2/JParseJsonLite",

src/twg2/parser/jsonLite/JsonLite.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package twg2.parser.jsonLite;
22

3-
43
/**
54
* @author TeamworkGuy2
65
* @since 2014-9-2
@@ -39,42 +38,42 @@ public enum NumberType {
3938
}
4039

4140

42-
public static final boolean isInt(JsonLite.NumberType numType) {
41+
public static final boolean isInt(NumberType numType) {
4342
return numType != null && numType == NumberType.INTEGER;
4443
}
4544

4645

47-
public static final boolean isLong(JsonLite.NumberType numType) {
46+
public static final boolean isLong(NumberType numType) {
4847
return numType != null && numType == NumberType.LONG;
4948
}
5049

5150

52-
public static final boolean isFloat(JsonLite.NumberType numType) {
51+
public static final boolean isFloat(NumberType numType) {
5352
return numType != null && numType == NumberType.FLOAT;
5453
}
5554

5655

57-
public static final boolean isDouble(JsonLite.NumberType numType) {
56+
public static final boolean isDouble(NumberType numType) {
5857
return numType != null && numType == NumberType.DOUBLE;
5958
}
6059

6160

62-
public static final boolean isIntLike(JsonLite.NumberType numType) {
61+
public static final boolean isIntLike(NumberType numType) {
6362
return numType != null && (numType == NumberType.INTEGER);
6463
}
6564

6665

67-
public static final boolean isLongLike(JsonLite.NumberType numType) {
66+
public static final boolean isLongLike(NumberType numType) {
6867
return numType != null && (numType == NumberType.LONG || numType == NumberType.INTEGER);
6968
}
7069

7170

72-
public static final boolean isFloatLike(JsonLite.NumberType numType) {
71+
public static final boolean isFloatLike(NumberType numType) {
7372
return numType != null && (numType == NumberType.FLOAT || numType == NumberType.INTEGER);
7473
}
7574

7675

77-
public static final boolean isDoubleLike(JsonLite.NumberType numType) {
76+
public static final boolean isDoubleLike(NumberType numType) {
7877
return numType != null && (numType == NumberType.DOUBLE || numType == NumberType.FLOAT || numType == NumberType.INTEGER || numType == NumberType.LONG);
7978
}
8079

src/twg2/parser/jsonLite/JsonLiteArray.java

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,11 @@
55
import java.util.ArrayList;
66
import java.util.List;
77

8-
import twg2.parser.textParser.TextIteratorParser;
8+
import twg2.parser.textParser.TextCharsParser;
99
import twg2.parser.textParser.TextParser;
1010
import twg2.parser.textParserUtils.ReadIsMatching;
1111
import twg2.parser.textParserUtils.ReadMatching;
1212
import twg2.parser.textParserUtils.ReadWhitespace;
13-
import twg2.text.stringEscape.StringEscape;
1413
import twg2.text.stringUtils.StringCheck;
1514

1615
/**
@@ -20,29 +19,6 @@
2019
public class JsonLiteArray {
2120
private static final char ARRAY_START = '[';
2221
private static final char ARRAY_END = ']';
23-
//private static final char[] notStringArrayLike = new char[] {' '/*space*/, ' '/*tab*/, ',', ARRAY_END};
24-
25-
26-
/** Convert an array of strings to a JSON styled array of strings (i.e. {@code ["a", "b", "c"]})
27-
*/
28-
public static final String stringifyArray(List<String> ary) throws IOException {
29-
StringBuilder strB = new StringBuilder(ary.size() > 10 ? ary.size() > 20 ? 128 : 64 : 32);
30-
strB.append(ARRAY_START);
31-
if(ary.size() > 0) {
32-
for(int i = 0, size = ary.size() - 1; i < size; i++) {
33-
strB.append('"');
34-
// replace \ and " with \\ and \"
35-
StringEscape.escape(ary.get(i), '\\', '\\', '"', strB);
36-
strB.append("\", ");
37-
}
38-
strB.append('"');
39-
StringEscape.escape(ary.get(ary.size()-1), '\\', '\\', '"', strB);
40-
strB.append('"');
41-
}
42-
strB.append(ARRAY_END);
43-
44-
return strB.toString();
45-
}
4622

4723

4824
/**
@@ -59,7 +35,7 @@ public static final List<String> parseArray(String arrayString) {
5935
* @see JsonLiteArray#parseArray(TextParser, boolean, List)
6036
*/
6137
public static final void parseArray(String arrayString, List<String> dst) {
62-
parseArray(TextIteratorParser.of(arrayString), true, dst);
38+
parseArray(TextCharsParser.of(arrayString), true, dst);
6339
}
6440

6541

src/twg2/parser/jsonLite/JsonLiteNumber.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package twg2.parser.jsonLite;
22

3+
import twg2.parser.jsonLite.JsonLite.NumberType;
34
import twg2.parser.textParser.TextParser;
45

56
/**
67
* @author TeamworkGuy2
78
* @since 2014-9-2
89
*/
910
public class JsonLiteNumber {
10-
private JsonLite.NumberType numberType;
11+
private NumberType numberType;
1112
// TODO all int and float values can be represented by longs and doubles, remove the unnecessary fields
1213
private int intVal;
1314
private long longVal;
@@ -40,7 +41,7 @@ public JsonLiteNumber(double doubleVal) {
4041

4142

4243
public void setInt(int intVal) {
43-
this.numberType = JsonLite.NumberType.INTEGER;
44+
this.numberType = NumberType.INTEGER;
4445
this.intVal = intVal;
4546
this.longVal = intVal;
4647
this.floatVal = intVal;
@@ -49,35 +50,35 @@ public void setInt(int intVal) {
4950

5051

5152
public void setLong(long longVal) {
52-
this.numberType = JsonLite.NumberType.LONG;
53+
this.numberType = NumberType.LONG;
5354
this.longVal = longVal;
5455
this.doubleVal = longVal;
5556
}
5657

5758

5859
public void setFloat(float floatVal) {
59-
this.numberType = JsonLite.NumberType.FLOAT;
60+
this.numberType = NumberType.FLOAT;
6061
this.floatVal = floatVal;
6162
this.doubleVal = floatVal;
6263
}
6364

6465

6566
public void setDouble(double doubleVal) {
66-
this.numberType = JsonLite.NumberType.DOUBLE;
67+
this.numberType = NumberType.DOUBLE;
6768
this.doubleVal = doubleVal;
6869
}
6970

7071

71-
public JsonLite.NumberType getNumberType() {
72+
public NumberType getNumberType() {
7273
return numberType;
7374
}
7475

7576

7677
public int asInt() {
77-
if(!JsonLite.NumberType.isIntLike(numberType)) {
78+
if(!NumberType.isIntLike(numberType)) {
7879
throw new IllegalStateException("cannot get int value from " + (numberType != null ? numberType.getPrimitiveTypeName() : "number") + " without precision loss");
7980
}
80-
if(numberType == JsonLite.NumberType.INTEGER) {
81+
if(numberType == NumberType.INTEGER) {
8182
return intVal;
8283
}
8384
else {
@@ -87,7 +88,7 @@ public int asInt() {
8788

8889

8990
public long asLong() {
90-
if(!JsonLite.NumberType.isLongLike(numberType)) {
91+
if(!NumberType.isLongLike(numberType)) {
9192
throw new IllegalStateException("cannot get long value from " + (numberType != null ? numberType.getPrimitiveTypeName() : "null") + " without precision loss");
9293
}
9394
switch(numberType) {
@@ -102,7 +103,7 @@ public long asLong() {
102103

103104

104105
public float asFloat() {
105-
if(!JsonLite.NumberType.isFloatLike(numberType)) {
106+
if(!NumberType.isFloatLike(numberType)) {
106107
throw new IllegalStateException("cannot get float value from " + (numberType != null ? numberType.getPrimitiveTypeName() : "null") + " without precision loss");
107108
}
108109
switch(numberType) {
@@ -117,7 +118,7 @@ public float asFloat() {
117118

118119

119120
public double asDouble() {
120-
if(!JsonLite.NumberType.isDoubleLike(numberType)) {
121+
if(!NumberType.isDoubleLike(numberType)) {
121122
throw new IllegalStateException("cannot get double value from " + (numberType != null ? numberType.getPrimitiveTypeName() : "null") + " without precision loss");
122123
}
123124
switch(numberType) {
@@ -137,7 +138,7 @@ public double asDouble() {
137138

138139
@Override
139140
public String toString() {
140-
return (numberType != null ? (JsonLite.NumberType.isLongLike(numberType) ? (numberType.getPrimitiveTypeName() + " " + asLong()) : (numberType.getPrimitiveTypeName() + " " + asDouble())) : "null numeric");
141+
return (numberType != null ? (NumberType.isLongLike(numberType) ? (numberType.getPrimitiveTypeName() + " " + asLong()) : (numberType.getPrimitiveTypeName() + " " + asDouble())) : "null numeric");
141142
}
142143

143144

test/twg2/parser/jsonLite/test/JsonLiteArrayTest.java

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
import org.junit.Assert;
88
import org.junit.Test;
99

10+
import twg2.junitassist.checks.CheckTask;
1011
import twg2.parser.jsonLite.JsonLiteArray;
11-
import twg2.parser.textParser.TextIteratorParser;
12+
import twg2.parser.textParser.TextCharsParser;
1213
import twg2.parser.textParser.TextParser;
13-
import checks.CheckTask;
1414

1515
/**
1616
* @author TeamworkGuy2
@@ -59,16 +59,20 @@ public void arrayParseTest() {
5959

6060
Assert.assertEquals("inputs and expected result arrays must be the same length", input.length, expect.length);
6161

62+
CheckTask.assertTests(input, expect, (str) -> {
63+
return JsonLiteArray.parseArray(str.substring(offset, str.length()));
64+
});
65+
6266
CheckTask.assertTests(input, expect, (str) -> {
6367
List<String> res = new ArrayList<>();
64-
JsonLiteArray.parseArray(TextIteratorParser.of(str, offset, str.length() - offset), true, res);
68+
JsonLiteArray.parseArray(parser(str, offset, str.length() - offset), true, res);
6569
return res;
6670
});
6771

6872
CheckTask.assertTests(input, expect, (str) -> {
6973
List<String> res = new ArrayList<>();
70-
TextParser lineBuf = TextIteratorParser.of(str);
71-
for(int i = 0; i < offset; i++) { lineBuf.nextChar(); }
74+
TextParser lineBuf = parser(str);
75+
lineBuf.skip(offset);
7276

7377
JsonLiteArray.parseArray(lineBuf, true, res);
7478
return res;
@@ -86,8 +90,8 @@ public void arrayLineParseTest() {
8690

8791
CheckTask.assertTests(input, expect, null, (str) -> {
8892
List<String> res = new ArrayList<>();
89-
TextParser lineBuf = TextIteratorParser.of(str);
90-
for(int i = 0; i < offset; i++) { lineBuf.nextChar(); }
93+
TextParser lineBuf = parser(str);
94+
lineBuf.skip(offset);
9195

9296
JsonLiteArray.parseArrayLine(lineBuf, true, res);
9397
return res;
@@ -117,12 +121,22 @@ public void readJsonLiteArrayTest() {
117121
Assert.assertEquals("array lengths", strs.length, expect.length);
118122

119123
for(int i = 0, size = strs.length; i < size; i++) {
120-
List<Object> elems = new ArrayList<>();
121-
JsonLiteArray.parseArrayDeep(TextIteratorParser.of(strs[i]), true, elems);
122-
CheckTask.assertTests(expect[i], elems.toArray(new Object[0]), (aryStrs) -> aryStrs);
124+
List<Object> parsedRes = new ArrayList<>();
123125

124-
//System.out.println("parsing JsonLite array '" + strs[i] + "': " + elems.toString());
126+
JsonLiteArray.parseArrayDeep(parser(strs[i]), true, parsedRes);
127+
128+
CheckTask.assertTests(expect[i], parsedRes.toArray(new Object[0]), (aryStrs) -> aryStrs);
125129
}
126130
}
127131

132+
133+
private static TextParser parser(String src) {
134+
return TextCharsParser.of(src);
135+
}
136+
137+
138+
private static TextParser parser(String src, int off, int len) {
139+
return TextCharsParser.of(src, off, len);
140+
}
141+
128142
}

0 commit comments

Comments
 (0)