Skip to content

Commit c42f565

Browse files
authored
Merge pull request #38 from netplex/v2.2.2
V2.2.2
2 parents cb03bcb + 29dd02d commit c42f565

30 files changed

+99
-63
lines changed

.gitignore

+6-21
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
1-
2-
/json-smart/target
3-
/json-smart/.settings
4-
/json-smart/.classpath
5-
/json-smart/.project
6-
/parent/.project
7-
/parent/.settings
8-
/json-smart/src/test/java/asm
9-
/asm/.classpath
10-
/asm/.project
11-
/asm/.settings
12-
/asm/targetjson-smart-backport/.classpath
13-
json-smart-backport/.project
14-
json-smart-backport/.settings
15-
asm/target/
16-
json-smart-backport/target/
17-
json-smart/target/
18-
**/.project
1+
**/.classpath
2+
**/.idea/
3+
**/.project
4+
**/.settings/
5+
**/*.iml
196
**/bin
20-
*.classpath
21-
*.project
22-
*.prefs
7+
**/target

accessors-smart/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>net.minidev</groupId>
55
<artifactId>accessors-smart</artifactId>
6-
<version>1.1</version>
6+
<version>1.2</version>
77
<name>ASM based accessors helper used by json-smart</name>
88
<description>Java reflect give poor performance on getter setter an constructor calls, accessors-smart use ASM to speed up those calls.
99
</description>

accessors-smart/src/main/java/net/minidev/asm/ConvertDate.java

+20-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.HashSet;
99
import java.util.Locale;
1010
import java.util.StringTokenizer;
11+
import java.util.TimeZone;
1112
import java.util.TreeMap;
1213

1314
public class ConvertDate {
@@ -40,6 +41,7 @@ private static Integer parseMonth(String s1) {
4041
static {
4142
voidData.add("CET");
4243
voidData.add("MEZ");
44+
voidData.add("PST");
4345
voidData.add("Uhr");
4446
voidData.add("h");
4547
voidData.add("pm");
@@ -118,6 +120,8 @@ public static Date convertToDate(Object obj) {
118120
return null;
119121
if (obj instanceof Date)
120122
return (Date) obj;
123+
if (obj instanceof Number)
124+
return new Date(((Number)obj).longValue());
121125
if (obj instanceof String) {
122126
StringTokenizer st = new StringTokenizer((String) obj, " -/:,.+");
123127
String s1 = "";
@@ -204,8 +208,12 @@ private static Date getMMDDYYYY(StringTokenizer st, String s1) {
204208
return null;
205209
s1 = st.nextToken();
206210
}
207-
cal.set(Calendar.YEAR, getYear(s1));
208-
211+
if (s1.length() == 4)
212+
cal.set(Calendar.YEAR, getYear(s1));
213+
else if (s1.length() == 2) {
214+
return addHour2(st, cal, s1);
215+
216+
}
209217
// /if (st.hasMoreTokens())
210218
// return null;
211219
// s1 = st.nextToken();
@@ -236,6 +244,10 @@ private static Date addHour(StringTokenizer st, Calendar cal, String s1) {
236244
return cal.getTime();
237245
s1 = st.nextToken();
238246
}
247+
return addHour2(st, cal, s1);
248+
}
249+
250+
private static Date addHour2(StringTokenizer st, Calendar cal, String s1) {
239251
cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(s1));
240252

241253
if (!st.hasMoreTokens())
@@ -273,13 +285,19 @@ private static Date addHour(StringTokenizer st, Calendar cal, String s1) {
273285
s1 = trySkip(st, s1, cal);
274286
// if (s1.equalsIgnoreCase("pm"))
275287
// cal.add(Calendar.HOUR_OF_DAY, 12);
288+
289+
if (s1.length() == 4 && Character.isDigit(s1.charAt(0)))
290+
cal.set(Calendar.YEAR, getYear(s1));
291+
276292
return cal.getTime();
277293
}
278294

279295
private static String trySkip(StringTokenizer st, String s1, Calendar cal) {
280296
while (voidData.contains(s1)) {
281297
if (s1.equalsIgnoreCase("pm"))
282298
cal.add(Calendar.HOUR_OF_DAY, 12);
299+
if (s1.equalsIgnoreCase("PST"))
300+
cal.setTimeZone(TimeZone.getTimeZone("PST"));
283301
if (!st.hasMoreTokens())
284302
return null;
285303
s1 = st.nextToken();

accessors-smart/src/test/java/net/minidev/asm/TestDateConvert.java

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public void testDateFR() throws Exception {
1717
tests.add("23 janvier 2012 13:42:12");
1818
tests.add("lundi 23 janvier 2012 13:42:12");
1919
tests.add("2012-01-23 13:42:12");
20+
tests.add("Thu Jan 23 13:42:12 PST 2012");
2021
//
2122
for (String testDate : tests) {
2223
Date parsed = null;

json-smart/pom.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>net.minidev</groupId>
55
<artifactId>json-smart</artifactId>
6-
<version>2.2.1</version>
6+
<version>2.2.2</version>
77
<name>JSON Small and Fast Parser</name>
88
<description>
99
JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.
@@ -47,7 +47,7 @@
4747
<dependency>
4848
<groupId>net.minidev</groupId>
4949
<artifactId>accessors-smart</artifactId>
50-
<version>1.1</version>
50+
<version>1.2</version>
5151
</dependency>
5252
</dependencies>
5353
<reporting>
@@ -95,7 +95,7 @@
9595
<!-- My old Is back -->
9696
<gpg.keyname>2C8DF6EC</gpg.keyname>
9797
<!-- <gpg.keyname>8E322ED0</gpg.keyname> -->
98-
<!-- <gpg.keyname>Uriel Chemouni (dev) <uchemouni@gmail.com></gpg.keyname> -->
98+
<!-- <gpg.keyname>Uriel Chemouni (dev) uchemouni@gmail.com</gpg.keyname> -->
9999
<!-- GPG Key ID to use for signing -->
100100
</properties>
101101
<build>
@@ -264,4 +264,4 @@
264264
</plugin>
265265
</plugins>
266266
</build>
267-
</project>
267+
</project>

json-smart/src/main/java/net/minidev/json/JSONArray.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
/**
2525
* A JSON array. JSONObject supports java.util.List interface.
2626
*
27-
* @author FangYidong<fangyidong@yahoo.com.cn>
28-
* @author Uriel Chemouni <uchemouni@gmail.com>
27+
* @author FangYidong &lt;fangyidong@yahoo.com.cn&gt;
28+
* @author Uriel Chemouni &lt;uchemouni@gmail.com&gt;
2929
*/
3030
public class JSONArray extends ArrayList<Object> implements List<Object>, JSONAwareEx, JSONStreamAwareEx {
3131
private static final long serialVersionUID = 9106884089231309568L;

json-smart/src/main/java/net/minidev/json/JSONAware.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Beans that support customized output of JSON text shall implement this
2020
* interface.
2121
*
22-
* @author FangYidong<fangyidong@yahoo.com.cn>
22+
* @author FangYidong &lt;fangyidong@yahoo.com.cn&gt;
2323
*/
2424
public interface JSONAware {
2525
/**

json-smart/src/main/java/net/minidev/json/JSONAwareEx.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* Adding compressions and formating features
2222
*
23-
* @author Uriel Chemouni <uchemouni@gmail.com>
23+
* @author Uriel Chemouni &lt;uchemouni@gmail.com&gt;
2424
*/
2525

2626
public interface JSONAwareEx extends JSONAware{

json-smart/src/main/java/net/minidev/json/JSONNavi.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* @since 1.0.9
2929
*
30-
* @author Uriel Chemouni <uchemouni@gmail.com>
30+
* @author Uriel Chemouni &lt;uchemouni@gmail.com&gt;
3131
*/
3232
public class JSONNavi<T> {
3333
private JsonReaderI<? super T> mapper;

json-smart/src/main/java/net/minidev/json/JSONObject.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
* A JSON object. Key value pairs are unordered. JSONObject supports
2626
* java.util.Map interface.
2727
*
28-
* @author FangYidong<fangyidong@yahoo.com.cn>
29-
* @author Uriel Chemouni <uchemouni@gmail.com>
28+
* @author FangYidong &lt;fangyidong@yahoo.com.cn&gt;
29+
* @author Uriel Chemouni &lt;uchemouni@gmail.com&gt;
3030
*/
3131
public class JSONObject extends HashMap<String, Object> implements JSONAware, JSONAwareEx, JSONStreamAwareEx {
3232
private static final long serialVersionUID = -503443796854799292L;
@@ -113,7 +113,6 @@ public String getAsString(String key) {
113113
/**
114114
* A Simple Helper cast an Object to an Number
115115
*
116-
* @see net.minidev.json.parser.JSONParserBase#parseNumber(String s)
117116
* @return a Number or null
118117
*/
119118
public Number getAsNumber(String key) {

json-smart/src/main/java/net/minidev/json/JSONStreamAware.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Beans that support customized output of JSON text to a writer shall implement
2222
* this interface.
2323
*
24-
* @author FangYidong<fangyidong@yahoo.com.cn>
24+
* @author FangYidong &lt;fangyidong@yahoo.com.cn&gt;
2525
*/
2626
public interface JSONStreamAware {
2727
/**

json-smart/src/main/java/net/minidev/json/JSONStreamAwareEx.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
* Beans that support customized output of JSON text to a writer shall implement
2222
* this interface.
2323
*
24-
* @author FangYidong<fangyidong@yahoo.com.cn>
24+
* @author FangYidong &lt;fangyidong@yahoo.com.cn&gt;
2525
*/
2626
public interface JSONStreamAwareEx extends JSONStreamAware {
2727
/**

json-smart/src/main/java/net/minidev/json/JSONStyle.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* JSONStyle object configure JSonSerializer reducing output size
2525
*
26-
* @author Uriel Chemouni <uchemouni@gmail.com>
26+
* @author Uriel Chemouni &lt;uchemouni@gmail.com&gt;
2727
*/
2828
public class JSONStyle {
2929
/**
@@ -57,7 +57,7 @@ public class JSONStyle {
5757
private boolean _protect4Web;
5858
private boolean _protectValues;
5959
private boolean _ignore_null;
60-
60+
6161
private MustProtect mpKey;
6262
private MustProtect mpValue;
6363

json-smart/src/main/java/net/minidev/json/JSONValue.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* The most commonly use methode are {@link #parse(String)}
4343
* {@link #toJSONString(Object)}
4444
*
45-
* @author Uriel Chemouni <uchemouni@gmail.com>
45+
* @author Uriel Chemouni &lt;uchemouni@gmail.com&gt;
4646
*/
4747
public class JSONValue {
4848
/**

json-smart/src/main/java/net/minidev/json/JStylerObj.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
/**
2121
* protected class used to stored Internal methods
2222
*
23-
* @author Uriel Chemouni <uchemouni@gmail.com>
23+
* @author Uriel Chemouni &lt;uchemouni@gmail.com&gt;
2424
*/
2525
class JStylerObj {
2626

@@ -181,7 +181,13 @@ public static boolean isSpecial(char c) {
181181
}
182182

183183
public static boolean isUnicode(char c) {
184-
return ((c >= '\u0000' && c <= '\u001F') || (c >= '\u007F' && c <= '\u009F') || (c >= '\u2000' && c <= '\u20FF'));
184+
// ANSI controle char
185+
return ((c >= '\u0000' && c <= '\u001F') ||
186+
// DEL or unicode ctrl
187+
(c >= '\u007F' && c <= '\u009F') ||
188+
// '\u00A0' No-breakable space ?
189+
// En Quad .. more
190+
(c >= '\u2000' && c <= '\u20FF'));
185191
}
186192

187193
public static boolean isKeyword(String s) {

json-smart/src/main/java/net/minidev/json/parser/JSONParser.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ public class JSONParser {
8080
* @since 2.0.1
8181
*/
8282
public final static int ACCEPT_TAILLING_SPACE = 512;
83+
/**
84+
* smart mode, fastest parsing mode. accept lots of non standard json syntax
85+
*
86+
* @since 2.2.2
87+
*/
88+
public final static int REJECT_127_CHAR = 1024;
89+
90+
8391
/**
8492
* smart mode, fastest parsing mode. accept lots of non standard json syntax
8593
*
@@ -101,13 +109,13 @@ public class JSONParser {
101109
*
102110
* @since 1.0.7
103111
*/
104-
public final static int MODE_JSON_SIMPLE = ACCEPT_USELESS_COMMA | USE_HI_PRECISION_FLOAT | ACCEPT_TAILLING_DATA | ACCEPT_TAILLING_SPACE;
112+
public final static int MODE_JSON_SIMPLE = ACCEPT_USELESS_COMMA | USE_HI_PRECISION_FLOAT | ACCEPT_TAILLING_DATA | ACCEPT_TAILLING_SPACE | REJECT_127_CHAR;
105113
/**
106114
* Strictest parsing mode
107115
*
108116
* @since 2.0.1
109117
*/
110-
public final static int MODE_STRICTEST = USE_INTEGER_STORAGE | USE_HI_PRECISION_FLOAT;
118+
public final static int MODE_STRICTEST = USE_INTEGER_STORAGE | USE_HI_PRECISION_FLOAT | REJECT_127_CHAR;
111119
/**
112120
* Default json-smart processing mode
113121
*/

json-smart/src/main/java/net/minidev/json/parser/JSONParserBase.java

+15-5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import java.math.BigDecimal;
2626
import java.math.BigInteger;
2727

28+
import org.omg.stub.java.rmi._Remote_Stub;
29+
2830
import net.minidev.json.writer.JsonReader;
2931
import net.minidev.json.writer.JsonReaderI;
3032

@@ -35,7 +37,7 @@
3537
* @see JSONParserMemory
3638
* @see JSONParserStream
3739
*
38-
* @author Uriel Chemouni <uchemouni@gmail.com>
40+
* @author Uriel Chemouni &lt;uchemouni@gmail.com&gt;
3941
*/
4042
abstract class JSONParserBase {
4143
protected char c;
@@ -82,6 +84,7 @@ abstract class JSONParserBase {
8284
protected final boolean ignoreControlChar;
8385
protected final boolean useHiPrecisionFloat;
8486
protected final boolean useIntegerStorage;
87+
protected final boolean reject127;
8588

8689
public JSONParserBase(int permissiveMode) {
8790
this.acceptNaN = (permissiveMode & JSONParser.ACCEPT_NAN) > 0;
@@ -94,6 +97,7 @@ public JSONParserBase(int permissiveMode) {
9497
this.useHiPrecisionFloat = (permissiveMode & JSONParser.USE_HI_PRECISION_FLOAT) > 0;
9598
this.checkTaillingData = (permissiveMode & (JSONParser.ACCEPT_TAILLING_DATA | JSONParser.ACCEPT_TAILLING_SPACE)) != (JSONParser.ACCEPT_TAILLING_DATA | JSONParser.ACCEPT_TAILLING_SPACE);
9699
this.checkTaillingSpace = (permissiveMode & JSONParser.ACCEPT_TAILLING_SPACE) == 0;
100+
this.reject127 = (permissiveMode & JSONParser.REJECT_127_CHAR) > 0;
97101
}
98102

99103
public void checkControleChar() throws ParseException {
@@ -106,8 +110,10 @@ public void checkControleChar() throws ParseException {
106110
continue;
107111
if (c <= 31)
108112
throw new ParseException(pos + i, ParseException.ERROR_UNEXPECTED_CHAR, c);
109-
if (c == 127)
110-
throw new ParseException(pos + i, ParseException.ERROR_UNEXPECTED_CHAR, c);
113+
if (c == 127) {
114+
if (reject127)
115+
throw new ParseException(pos + i, ParseException.ERROR_UNEXPECTED_CHAR, c);
116+
}
111117
}
112118
}
113119

@@ -656,16 +662,20 @@ protected void readString2() throws ParseException, IOException {
656662
case (char) 23: // End transmission block, not the same as EOT
657663
case (char) 24: // Cancel line, MPE echoes !!!
658664
case (char) 25: // End of medium, Control-Y interrupt
659-
// case (char) 26: // Substitute
665+
// case (char) 26: // Substitute == EOI
660666
case (char) 27: // escape
661667
case (char) 28: // File Separator
662668
case (char) 29: // Group Separator
663669
case (char) 30: // Record Separator
664670
case (char) 31: // Unit Separator
671+
if (ignoreControlChar)
672+
continue;
673+
throw new ParseException(pos, ERROR_UNEXPECTED_CHAR, c);
665674
case (char) 127: // del
666675
if (ignoreControlChar)
667676
continue;
668-
throw new ParseException(pos, ERROR_UNEXPECTED_CHAR, c);
677+
if (reject127)
678+
throw new ParseException(pos, ERROR_UNEXPECTED_CHAR, c);
669679
default:
670680
sb.append(c);
671681
}

json-smart/src/main/java/net/minidev/json/parser/JSONParserByteArray.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/**
2323
* Parser for JSON text. Please note that JSONParser is NOT thread-safe.
2424
*
25-
* @author Uriel Chemouni <uchemouni@gmail.com>
25+
* @author Uriel Chemouni &lt;uchemouni@gmail.com&gt;
2626
*/
2727
class JSONParserByteArray extends JSONParserMemory {
2828
private byte[] in;

json-smart/src/main/java/net/minidev/json/parser/JSONParserInputStream.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
/**
2525
* Parser for JSON text. Please note that JSONParser is NOT thread-safe.
2626
*
27-
* @author Uriel Chemouni <uchemouni@gmail.com>
27+
* @author Uriel Chemouni &lt;uchemouni@gmail.com&gt;
2828
*/
2929
class JSONParserInputStream extends JSONParserReader {
3030

0 commit comments

Comments
 (0)