Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V2.2.2 #38

Merged
merged 6 commits into from
Mar 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 6 additions & 21 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@

/json-smart/target
/json-smart/.settings
/json-smart/.classpath
/json-smart/.project
/parent/.project
/parent/.settings
/json-smart/src/test/java/asm
/asm/.classpath
/asm/.project
/asm/.settings
/asm/targetjson-smart-backport/.classpath
json-smart-backport/.project
json-smart-backport/.settings
asm/target/
json-smart-backport/target/
json-smart/target/
**/.project
**/.classpath
**/.idea/
**/.project
**/.settings/
**/*.iml
**/bin
*.classpath
*.project
*.prefs
**/target
2 changes: 1 addition & 1 deletion accessors-smart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.minidev</groupId>
<artifactId>accessors-smart</artifactId>
<version>1.1</version>
<version>1.2</version>
<name>ASM based accessors helper used by json-smart</name>
<description>Java reflect give poor performance on getter setter an constructor calls, accessors-smart use ASM to speed up those calls.
</description>
Expand Down
22 changes: 20 additions & 2 deletions accessors-smart/src/main/java/net/minidev/asm/ConvertDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.HashSet;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.TimeZone;
import java.util.TreeMap;

public class ConvertDate {
Expand Down Expand Up @@ -40,6 +41,7 @@ private static Integer parseMonth(String s1) {
static {
voidData.add("CET");
voidData.add("MEZ");
voidData.add("PST");
voidData.add("Uhr");
voidData.add("h");
voidData.add("pm");
Expand Down Expand Up @@ -118,6 +120,8 @@ public static Date convertToDate(Object obj) {
return null;
if (obj instanceof Date)
return (Date) obj;
if (obj instanceof Number)
return new Date(((Number)obj).longValue());
if (obj instanceof String) {
StringTokenizer st = new StringTokenizer((String) obj, " -/:,.+");
String s1 = "";
Expand Down Expand Up @@ -204,8 +208,12 @@ private static Date getMMDDYYYY(StringTokenizer st, String s1) {
return null;
s1 = st.nextToken();
}
cal.set(Calendar.YEAR, getYear(s1));

if (s1.length() == 4)
cal.set(Calendar.YEAR, getYear(s1));
else if (s1.length() == 2) {
return addHour2(st, cal, s1);

}
// /if (st.hasMoreTokens())
// return null;
// s1 = st.nextToken();
Expand Down Expand Up @@ -236,6 +244,10 @@ private static Date addHour(StringTokenizer st, Calendar cal, String s1) {
return cal.getTime();
s1 = st.nextToken();
}
return addHour2(st, cal, s1);
}

private static Date addHour2(StringTokenizer st, Calendar cal, String s1) {
cal.set(Calendar.HOUR_OF_DAY, Integer.parseInt(s1));

if (!st.hasMoreTokens())
Expand Down Expand Up @@ -273,13 +285,19 @@ private static Date addHour(StringTokenizer st, Calendar cal, String s1) {
s1 = trySkip(st, s1, cal);
// if (s1.equalsIgnoreCase("pm"))
// cal.add(Calendar.HOUR_OF_DAY, 12);

if (s1.length() == 4 && Character.isDigit(s1.charAt(0)))
cal.set(Calendar.YEAR, getYear(s1));

return cal.getTime();
}

private static String trySkip(StringTokenizer st, String s1, Calendar cal) {
while (voidData.contains(s1)) {
if (s1.equalsIgnoreCase("pm"))
cal.add(Calendar.HOUR_OF_DAY, 12);
if (s1.equalsIgnoreCase("PST"))
cal.setTimeZone(TimeZone.getTimeZone("PST"));
if (!st.hasMoreTokens())
return null;
s1 = st.nextToken();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public void testDateFR() throws Exception {
tests.add("23 janvier 2012 13:42:12");
tests.add("lundi 23 janvier 2012 13:42:12");
tests.add("2012-01-23 13:42:12");
tests.add("Thu Jan 23 13:42:12 PST 2012");
//
for (String testDate : tests) {
Date parsed = null;
Expand Down
8 changes: 4 additions & 4 deletions json-smart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.2.1</version>
<version>2.2.2</version>
<name>JSON Small and Fast Parser</name>
<description>
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.
Expand Down Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>net.minidev</groupId>
<artifactId>accessors-smart</artifactId>
<version>1.1</version>
<version>1.2</version>
</dependency>
</dependencies>
<reporting>
Expand Down Expand Up @@ -95,7 +95,7 @@
<!-- My old Is back -->
<gpg.keyname>2C8DF6EC</gpg.keyname>
<!-- <gpg.keyname>8E322ED0</gpg.keyname> -->
<!-- <gpg.keyname>Uriel Chemouni (dev) <[email protected]></gpg.keyname> -->
<!-- <gpg.keyname>Uriel Chemouni (dev) [email protected]</gpg.keyname> -->
<!-- GPG Key ID to use for signing -->
</properties>
<build>
Expand Down Expand Up @@ -264,4 +264,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
4 changes: 2 additions & 2 deletions json-smart/src/main/java/net/minidev/json/JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
/**
* A JSON array. JSONObject supports java.util.List interface.
*
* @author FangYidong<[email protected]>
* @author Uriel Chemouni <[email protected]>
* @author FangYidong &lt;[email protected]&gt;
* @author Uriel Chemouni &lt;[email protected]&gt;
*/
public class JSONArray extends ArrayList<Object> implements List<Object>, JSONAwareEx, JSONStreamAwareEx {
private static final long serialVersionUID = 9106884089231309568L;
Expand Down
2 changes: 1 addition & 1 deletion json-smart/src/main/java/net/minidev/json/JSONAware.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* Beans that support customized output of JSON text shall implement this
* interface.
*
* @author FangYidong<[email protected]>
* @author FangYidong &lt;[email protected]&gt;
*/
public interface JSONAware {
/**
Expand Down
2 changes: 1 addition & 1 deletion json-smart/src/main/java/net/minidev/json/JSONAwareEx.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* Adding compressions and formating features
*
* @author Uriel Chemouni <[email protected]>
* @author Uriel Chemouni &lt;[email protected]&gt;
*/

public interface JSONAwareEx extends JSONAware{
Expand Down
2 changes: 1 addition & 1 deletion json-smart/src/main/java/net/minidev/json/JSONNavi.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @since 1.0.9
*
* @author Uriel Chemouni <[email protected]>
* @author Uriel Chemouni &lt;[email protected]&gt;
*/
public class JSONNavi<T> {
private JsonReaderI<? super T> mapper;
Expand Down
5 changes: 2 additions & 3 deletions json-smart/src/main/java/net/minidev/json/JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
* A JSON object. Key value pairs are unordered. JSONObject supports
* java.util.Map interface.
*
* @author FangYidong<[email protected]>
* @author Uriel Chemouni <[email protected]>
* @author FangYidong &lt;[email protected]&gt;
* @author Uriel Chemouni &lt;[email protected]&gt;
*/
public class JSONObject extends HashMap<String, Object> implements JSONAware, JSONAwareEx, JSONStreamAwareEx {
private static final long serialVersionUID = -503443796854799292L;
Expand Down Expand Up @@ -113,7 +113,6 @@ public String getAsString(String key) {
/**
* A Simple Helper cast an Object to an Number
*
* @see net.minidev.json.parser.JSONParserBase#parseNumber(String s)
* @return a Number or null
*/
public Number getAsNumber(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Beans that support customized output of JSON text to a writer shall implement
* this interface.
*
* @author FangYidong<[email protected]>
* @author FangYidong &lt;[email protected]&gt;
*/
public interface JSONStreamAware {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* Beans that support customized output of JSON text to a writer shall implement
* this interface.
*
* @author FangYidong<[email protected]>
* @author FangYidong &lt;[email protected]&gt;
*/
public interface JSONStreamAwareEx extends JSONStreamAware {
/**
Expand Down
4 changes: 2 additions & 2 deletions json-smart/src/main/java/net/minidev/json/JSONStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* JSONStyle object configure JSonSerializer reducing output size
*
* @author Uriel Chemouni <[email protected]>
* @author Uriel Chemouni &lt;[email protected]&gt;
*/
public class JSONStyle {
/**
Expand Down Expand Up @@ -57,7 +57,7 @@ public class JSONStyle {
private boolean _protect4Web;
private boolean _protectValues;
private boolean _ignore_null;

private MustProtect mpKey;
private MustProtect mpValue;

Expand Down
2 changes: 1 addition & 1 deletion json-smart/src/main/java/net/minidev/json/JSONValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* The most commonly use methode are {@link #parse(String)}
* {@link #toJSONString(Object)}
*
* @author Uriel Chemouni <[email protected]>
* @author Uriel Chemouni &lt;[email protected]&gt;
*/
public class JSONValue {
/**
Expand Down
10 changes: 8 additions & 2 deletions json-smart/src/main/java/net/minidev/json/JStylerObj.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* protected class used to stored Internal methods
*
* @author Uriel Chemouni <[email protected]>
* @author Uriel Chemouni &lt;[email protected]&gt;
*/
class JStylerObj {

Expand Down Expand Up @@ -181,7 +181,13 @@ public static boolean isSpecial(char c) {
}

public static boolean isUnicode(char c) {
return ((c >= '\u0000' && c <= '\u001F') || (c >= '\u007F' && c <= '\u009F') || (c >= '\u2000' && c <= '\u20FF'));
// ANSI controle char
return ((c >= '\u0000' && c <= '\u001F') ||
// DEL or unicode ctrl
(c >= '\u007F' && c <= '\u009F') ||
// '\u00A0' No-breakable space ?
// En Quad .. more
(c >= '\u2000' && c <= '\u20FF'));
}

public static boolean isKeyword(String s) {
Expand Down
12 changes: 10 additions & 2 deletions json-smart/src/main/java/net/minidev/json/parser/JSONParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ public class JSONParser {
* @since 2.0.1
*/
public final static int ACCEPT_TAILLING_SPACE = 512;
/**
* smart mode, fastest parsing mode. accept lots of non standard json syntax
*
* @since 2.2.2
*/
public final static int REJECT_127_CHAR = 1024;


/**
* smart mode, fastest parsing mode. accept lots of non standard json syntax
*
Expand All @@ -101,13 +109,13 @@ public class JSONParser {
*
* @since 1.0.7
*/
public final static int MODE_JSON_SIMPLE = ACCEPT_USELESS_COMMA | USE_HI_PRECISION_FLOAT | ACCEPT_TAILLING_DATA | ACCEPT_TAILLING_SPACE;
public final static int MODE_JSON_SIMPLE = ACCEPT_USELESS_COMMA | USE_HI_PRECISION_FLOAT | ACCEPT_TAILLING_DATA | ACCEPT_TAILLING_SPACE | REJECT_127_CHAR;
/**
* Strictest parsing mode
*
* @since 2.0.1
*/
public final static int MODE_STRICTEST = USE_INTEGER_STORAGE | USE_HI_PRECISION_FLOAT;
public final static int MODE_STRICTEST = USE_INTEGER_STORAGE | USE_HI_PRECISION_FLOAT | REJECT_127_CHAR;
/**
* Default json-smart processing mode
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.math.BigDecimal;
import java.math.BigInteger;

import org.omg.stub.java.rmi._Remote_Stub;

import net.minidev.json.writer.JsonReader;
import net.minidev.json.writer.JsonReaderI;

Expand All @@ -35,7 +37,7 @@
* @see JSONParserMemory
* @see JSONParserStream
*
* @author Uriel Chemouni <[email protected]>
* @author Uriel Chemouni &lt;[email protected]&gt;
*/
abstract class JSONParserBase {
protected char c;
Expand Down Expand Up @@ -82,6 +84,7 @@ abstract class JSONParserBase {
protected final boolean ignoreControlChar;
protected final boolean useHiPrecisionFloat;
protected final boolean useIntegerStorage;
protected final boolean reject127;

public JSONParserBase(int permissiveMode) {
this.acceptNaN = (permissiveMode & JSONParser.ACCEPT_NAN) > 0;
Expand All @@ -94,6 +97,7 @@ public JSONParserBase(int permissiveMode) {
this.useHiPrecisionFloat = (permissiveMode & JSONParser.USE_HI_PRECISION_FLOAT) > 0;
this.checkTaillingData = (permissiveMode & (JSONParser.ACCEPT_TAILLING_DATA | JSONParser.ACCEPT_TAILLING_SPACE)) != (JSONParser.ACCEPT_TAILLING_DATA | JSONParser.ACCEPT_TAILLING_SPACE);
this.checkTaillingSpace = (permissiveMode & JSONParser.ACCEPT_TAILLING_SPACE) == 0;
this.reject127 = (permissiveMode & JSONParser.REJECT_127_CHAR) > 0;
}

public void checkControleChar() throws ParseException {
Expand All @@ -106,8 +110,10 @@ public void checkControleChar() throws ParseException {
continue;
if (c <= 31)
throw new ParseException(pos + i, ParseException.ERROR_UNEXPECTED_CHAR, c);
if (c == 127)
throw new ParseException(pos + i, ParseException.ERROR_UNEXPECTED_CHAR, c);
if (c == 127) {
if (reject127)
throw new ParseException(pos + i, ParseException.ERROR_UNEXPECTED_CHAR, c);
}
}
}

Expand Down Expand Up @@ -656,16 +662,20 @@ protected void readString2() throws ParseException, IOException {
case (char) 23: // End transmission block, not the same as EOT
case (char) 24: // Cancel line, MPE echoes !!!
case (char) 25: // End of medium, Control-Y interrupt
// case (char) 26: // Substitute
// case (char) 26: // Substitute == EOI
case (char) 27: // escape
case (char) 28: // File Separator
case (char) 29: // Group Separator
case (char) 30: // Record Separator
case (char) 31: // Unit Separator
if (ignoreControlChar)
continue;
throw new ParseException(pos, ERROR_UNEXPECTED_CHAR, c);
case (char) 127: // del
if (ignoreControlChar)
continue;
throw new ParseException(pos, ERROR_UNEXPECTED_CHAR, c);
if (reject127)
throw new ParseException(pos, ERROR_UNEXPECTED_CHAR, c);
default:
sb.append(c);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
/**
* Parser for JSON text. Please note that JSONParser is NOT thread-safe.
*
* @author Uriel Chemouni <[email protected]>
* @author Uriel Chemouni &lt;[email protected]&gt;
*/
class JSONParserByteArray extends JSONParserMemory {
private byte[] in;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/**
* Parser for JSON text. Please note that JSONParser is NOT thread-safe.
*
* @author Uriel Chemouni <[email protected]>
* @author Uriel Chemouni &lt;[email protected]&gt;
*/
class JSONParserInputStream extends JSONParserReader {

Expand Down
Loading