mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-01 05:47:45 +01:00
More formatting
By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
parent
346e41a6e5
commit
05b2a299c0
@ -15,119 +15,122 @@ import java.util.StringTokenizer;
|
|||||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||||
*/
|
*/
|
||||||
public class ItemList {
|
public class ItemList {
|
||||||
private String sp=",";
|
private String sp = ",";
|
||||||
List items=new ArrayList();
|
List items = new ArrayList();
|
||||||
|
|
||||||
|
public ItemList() {
|
||||||
public ItemList(){}
|
|
||||||
|
|
||||||
|
|
||||||
public ItemList(String s){
|
|
||||||
this.split(s,sp,items);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemList(String s,String sp){
|
public ItemList(String s) {
|
||||||
this.sp=s;
|
this.split(s, sp, items);
|
||||||
this.split(s,sp,items);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemList(String s,String sp,boolean isMultiToken){
|
public ItemList(String s, String sp) {
|
||||||
split(s,sp,items,isMultiToken);
|
this.sp = s;
|
||||||
|
this.split(s, sp, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List getItems(){
|
public ItemList(String s, String sp, boolean isMultiToken) {
|
||||||
|
split(s, sp, items, isMultiToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List getItems() {
|
||||||
return this.items;
|
return this.items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] getArray(){
|
public String[] getArray() {
|
||||||
return (String[])this.items.toArray();
|
return (String[]) this.items.toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void split(String s,String sp,List append,boolean isMultiToken){
|
public void split(String s, String sp, List append, boolean isMultiToken) {
|
||||||
if(s==null || sp==null)
|
if (s == null || sp == null) {
|
||||||
return;
|
return;
|
||||||
if(isMultiToken){
|
}
|
||||||
StringTokenizer tokens=new StringTokenizer(s,sp);
|
if (isMultiToken) {
|
||||||
while(tokens.hasMoreTokens()){
|
StringTokenizer tokens = new StringTokenizer(s, sp);
|
||||||
|
while (tokens.hasMoreTokens()) {
|
||||||
append.add(tokens.nextToken().trim());
|
append.add(tokens.nextToken().trim());
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else{
|
this.split(s, sp, append);
|
||||||
this.split(s,sp,append);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void split(String s,String sp,List append){
|
public void split(String s, String sp, List append) {
|
||||||
if(s==null || sp==null)
|
if (s == null || sp == null) {
|
||||||
return;
|
return;
|
||||||
int pos=0;
|
}
|
||||||
int prevPos=0;
|
int pos = 0;
|
||||||
do{
|
int prevPos = 0;
|
||||||
prevPos=pos;
|
do {
|
||||||
pos=s.indexOf(sp,pos);
|
prevPos = pos;
|
||||||
if(pos==-1)
|
pos = s.indexOf(sp, pos);
|
||||||
|
if (pos == -1) {
|
||||||
break;
|
break;
|
||||||
append.add(s.substring(prevPos,pos).trim());
|
}
|
||||||
pos+=sp.length();
|
append.add(s.substring(prevPos, pos).trim());
|
||||||
}while(pos!=-1);
|
pos += sp.length();
|
||||||
|
} while (pos != -1);
|
||||||
append.add(s.substring(prevPos).trim());
|
append.add(s.substring(prevPos).trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSP(String sp){
|
public void setSP(String sp) {
|
||||||
this.sp=sp;
|
this.sp = sp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(int i,String item){
|
public void add(int i, String item) {
|
||||||
if(item==null)
|
if (item == null) {
|
||||||
return;
|
return;
|
||||||
items.add(i,item.trim());
|
}
|
||||||
|
items.add(i, item.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(String item){
|
public void add(String item) {
|
||||||
if(item==null)
|
if (item == null) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
items.add(item.trim());
|
items.add(item.trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAll(ItemList list){
|
public void addAll(ItemList list) {
|
||||||
items.addAll(list.items);
|
items.addAll(list.items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAll(String s){
|
public void addAll(String s) {
|
||||||
this.split(s,sp,items);
|
this.split(s, sp, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAll(String s,String sp){
|
public void addAll(String s, String sp) {
|
||||||
this.split(s,sp,items);
|
this.split(s, sp, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAll(String s,String sp,boolean isMultiToken){
|
public void addAll(String s, String sp, boolean isMultiToken) {
|
||||||
this.split(s,sp,items,isMultiToken);
|
this.split(s, sp, items, isMultiToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param i 0-based
|
* @param i 0-based
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public String get(int i){
|
public String get(int i) {
|
||||||
return (String)items.get(i);
|
return (String) items.get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int size(){
|
public int size() {
|
||||||
return items.size();
|
return items.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString() {
|
||||||
return toString(sp);
|
return toString(sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(String sp){
|
public String toString(String sp) {
|
||||||
StringBuffer sb=new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
for(int i=0;i<items.size();i++){
|
for (int i = 0; i < items.size(); i++) {
|
||||||
if(i==0)
|
if (i == 0) {
|
||||||
sb.append(items.get(i));
|
sb.append(items.get(i));
|
||||||
else{
|
} else {
|
||||||
sb.append(sp);
|
sb.append(sp);
|
||||||
sb.append(items.get(i));
|
sb.append(items.get(i));
|
||||||
}
|
}
|
||||||
@ -136,12 +139,12 @@ public class ItemList {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear(){
|
public void clear() {
|
||||||
items.clear();
|
items.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reset(){
|
public void reset() {
|
||||||
sp=",";
|
sp = ",";
|
||||||
items.clear();
|
items.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A JSON array. JSONObject supports java.util.List interface.
|
* A JSON array. JSONObject supports java.util.List interface.
|
||||||
*
|
*
|
||||||
@ -28,24 +27,25 @@ public class JSONArray extends ArrayList implements List, JSONAware, JSONStreamA
|
|||||||
* @param list
|
* @param list
|
||||||
* @param out
|
* @param out
|
||||||
*/
|
*/
|
||||||
public static void writeJSONString(List list, Writer out) throws IOException{
|
public static void writeJSONString(List list, Writer out) throws IOException {
|
||||||
if(list == null){
|
if (list == null) {
|
||||||
out.write("null");
|
out.write("null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
Iterator iter=list.iterator();
|
Iterator iter = list.iterator();
|
||||||
|
|
||||||
out.write('[');
|
out.write('[');
|
||||||
while(iter.hasNext()){
|
while (iter.hasNext()) {
|
||||||
if(first)
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
else
|
} else {
|
||||||
out.write(',');
|
out.write(',');
|
||||||
|
}
|
||||||
|
|
||||||
Object value=iter.next();
|
Object value = iter.next();
|
||||||
if(value == null){
|
if (value == null) {
|
||||||
out.write("null");
|
out.write("null");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ public class JSONArray extends ArrayList implements List, JSONAware, JSONStreamA
|
|||||||
out.write(']');
|
out.write(']');
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeJSONString(Writer out) throws IOException{
|
public void writeJSONString(Writer out) throws IOException {
|
||||||
writeJSONString(this, out);
|
writeJSONString(this, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,23 +68,25 @@ public class JSONArray extends ArrayList implements List, JSONAware, JSONStreamA
|
|||||||
* @param list
|
* @param list
|
||||||
* @return JSON text, or "null" if list is null.
|
* @return JSON text, or "null" if list is null.
|
||||||
*/
|
*/
|
||||||
public static String toJSONString(List list){
|
public static String toJSONString(List list) {
|
||||||
if(list == null)
|
if (list == null) {
|
||||||
return "null";
|
return "null";
|
||||||
|
}
|
||||||
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
Iterator iter=list.iterator();
|
Iterator iter = list.iterator();
|
||||||
|
|
||||||
sb.append('[');
|
sb.append('[');
|
||||||
while(iter.hasNext()){
|
while (iter.hasNext()) {
|
||||||
if(first)
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
else
|
} else {
|
||||||
sb.append(',');
|
sb.append(',');
|
||||||
|
}
|
||||||
|
|
||||||
Object value=iter.next();
|
Object value = iter.next();
|
||||||
if(value == null){
|
if (value == null) {
|
||||||
sb.append("null");
|
sb.append("null");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -94,14 +96,11 @@ public class JSONArray extends ArrayList implements List, JSONAware, JSONStreamA
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toJSONString(){
|
public String toJSONString() {
|
||||||
return toJSONString(this);
|
return toJSONString(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return toJSONString();
|
return toJSONString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ import java.util.Map;
|
|||||||
*
|
*
|
||||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||||
*/
|
*/
|
||||||
public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAware{
|
public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAware {
|
||||||
private static final long serialVersionUID = -503443796854799292L;
|
private static final long serialVersionUID = -503443796854799292L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,21 +28,22 @@ public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAwa
|
|||||||
* @param out
|
* @param out
|
||||||
*/
|
*/
|
||||||
public static void writeJSONString(Map map, Writer out) throws IOException {
|
public static void writeJSONString(Map map, Writer out) throws IOException {
|
||||||
if(map == null){
|
if (map == null) {
|
||||||
out.write("null");
|
out.write("null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
Iterator iter=map.entrySet().iterator();
|
Iterator iter = map.entrySet().iterator();
|
||||||
|
|
||||||
out.write('{');
|
out.write('{');
|
||||||
while(iter.hasNext()){
|
while (iter.hasNext()) {
|
||||||
if(first)
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
else
|
} else {
|
||||||
out.write(',');
|
out.write(',');
|
||||||
Map.Entry entry=(Map.Entry)iter.next();
|
}
|
||||||
|
Map.Entry entry = (Map.Entry) iter.next();
|
||||||
out.write('\"');
|
out.write('\"');
|
||||||
out.write(escape(String.valueOf(entry.getKey())));
|
out.write(escape(String.valueOf(entry.getKey())));
|
||||||
out.write('\"');
|
out.write('\"');
|
||||||
@ -52,7 +53,7 @@ public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAwa
|
|||||||
out.write('}');
|
out.write('}');
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeJSONString(Writer out) throws IOException{
|
public void writeJSONString(Writer out) throws IOException {
|
||||||
writeJSONString(this, out);
|
writeJSONString(this, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,38 +66,41 @@ public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAwa
|
|||||||
* @param map
|
* @param map
|
||||||
* @return JSON text, or "null" if map is null.
|
* @return JSON text, or "null" if map is null.
|
||||||
*/
|
*/
|
||||||
public static String toJSONString(Map map){
|
public static String toJSONString(Map map) {
|
||||||
if(map == null)
|
if (map == null) {
|
||||||
return "null";
|
return "null";
|
||||||
|
}
|
||||||
|
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
Iterator iter=map.entrySet().iterator();
|
Iterator iter = map.entrySet().iterator();
|
||||||
|
|
||||||
sb.append('{');
|
sb.append('{');
|
||||||
while(iter.hasNext()){
|
while (iter.hasNext()) {
|
||||||
if(first)
|
if (first) {
|
||||||
first = false;
|
first = false;
|
||||||
else
|
} else {
|
||||||
sb.append(',');
|
sb.append(',');
|
||||||
|
}
|
||||||
|
|
||||||
Map.Entry entry=(Map.Entry)iter.next();
|
Map.Entry entry = (Map.Entry) iter.next();
|
||||||
toJSONString(String.valueOf(entry.getKey()),entry.getValue(), sb);
|
toJSONString(String.valueOf(entry.getKey()), entry.getValue(), sb);
|
||||||
}
|
}
|
||||||
sb.append('}');
|
sb.append('}');
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toJSONString(){
|
public String toJSONString() {
|
||||||
return toJSONString(this);
|
return toJSONString(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String toJSONString(String key,Object value, StringBuffer sb){
|
private static String toJSONString(String key, Object value, StringBuffer sb) {
|
||||||
sb.append('\"');
|
sb.append('\"');
|
||||||
if(key == null)
|
if (key == null) {
|
||||||
sb.append("null");
|
sb.append("null");
|
||||||
else
|
} else {
|
||||||
JSONValue.escape(key, sb);
|
JSONValue.escape(key, sb);
|
||||||
|
}
|
||||||
sb.append('\"').append(':');
|
sb.append('\"').append(':');
|
||||||
|
|
||||||
sb.append(JSONValue.toJSONString(value));
|
sb.append(JSONValue.toJSONString(value));
|
||||||
@ -104,11 +108,11 @@ public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAwa
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString() {
|
||||||
return toJSONString();
|
return toJSONString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String toString(String key,Object value){
|
public static String toString(String key, Object value) {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
toJSONString(key, value, sb);
|
toJSONString(key, value, sb);
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
@ -123,7 +127,7 @@ public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAwa
|
|||||||
* @param s
|
* @param s
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String escape(String s){
|
public static String escape(String s) {
|
||||||
return JSONValue.escape(s);
|
return JSONValue.escape(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ import java.util.Map;
|
|||||||
import org.json.simple.parser.JSONParser;
|
import org.json.simple.parser.JSONParser;
|
||||||
import org.json.simple.parser.ParseException;
|
import org.json.simple.parser.ParseException;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||||
*/
|
*/
|
||||||
@ -36,18 +35,17 @@ public class JSONValue {
|
|||||||
* null
|
* null
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static Object parse(Reader in){
|
public static Object parse(Reader in) {
|
||||||
try{
|
try {
|
||||||
JSONParser parser=new JSONParser();
|
JSONParser parser = new JSONParser();
|
||||||
return parser.parse(in);
|
return parser.parse(in);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch(Exception e){
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object parse(String s){
|
public static Object parse(String s) {
|
||||||
StringReader in=new StringReader(s);
|
StringReader in = new StringReader(s);
|
||||||
return parse(in);
|
return parse(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,13 +66,13 @@ public class JSONValue {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws ParseException
|
* @throws ParseException
|
||||||
*/
|
*/
|
||||||
public static Object parseWithException(Reader in) throws IOException, ParseException{
|
public static Object parseWithException(Reader in) throws IOException, ParseException {
|
||||||
JSONParser parser=new JSONParser();
|
JSONParser parser = new JSONParser();
|
||||||
return parser.parse(in);
|
return parser.parse(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Object parseWithException(String s) throws ParseException{
|
public static Object parseWithException(String s) throws ParseException {
|
||||||
JSONParser parser=new JSONParser();
|
JSONParser parser = new JSONParser();
|
||||||
return parser.parse(s);
|
return parser.parse(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,61 +91,63 @@ public class JSONValue {
|
|||||||
* @param writer
|
* @param writer
|
||||||
*/
|
*/
|
||||||
public static void writeJSONString(Object value, Writer out) throws IOException {
|
public static void writeJSONString(Object value, Writer out) throws IOException {
|
||||||
if(value == null){
|
if (value == null) {
|
||||||
out.write("null");
|
out.write("null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value instanceof String){
|
if (value instanceof String) {
|
||||||
out.write('\"');
|
out.write('\"');
|
||||||
out.write(escape((String)value));
|
out.write(escape((String) value));
|
||||||
out.write('\"');
|
out.write('\"');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value instanceof Double){
|
if (value instanceof Double) {
|
||||||
if(((Double)value).isInfinite() || ((Double)value).isNaN())
|
if (((Double) value).isInfinite() || ((Double) value).isNaN()) {
|
||||||
out.write("null");
|
out.write("null");
|
||||||
else
|
} else {
|
||||||
out.write(value.toString());
|
out.write(value.toString());
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value instanceof Float){
|
if (value instanceof Float) {
|
||||||
if(((Float)value).isInfinite() || ((Float)value).isNaN())
|
if (((Float) value).isInfinite() || ((Float) value).isNaN()) {
|
||||||
out.write("null");
|
out.write("null");
|
||||||
else
|
} else {
|
||||||
|
out.write(value.toString());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value instanceof Number) {
|
||||||
out.write(value.toString());
|
out.write(value.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value instanceof Number){
|
if (value instanceof Boolean) {
|
||||||
out.write(value.toString());
|
out.write(value.toString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value instanceof Boolean){
|
if ((value instanceof JSONStreamAware)) {
|
||||||
out.write(value.toString());
|
((JSONStreamAware) value).writeJSONString(out);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((value instanceof JSONStreamAware)){
|
if ((value instanceof JSONAware)) {
|
||||||
((JSONStreamAware)value).writeJSONString(out);
|
out.write(((JSONAware) value).toJSONString());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if((value instanceof JSONAware)){
|
if (value instanceof Map) {
|
||||||
out.write(((JSONAware)value).toJSONString());
|
JSONObject.writeJSONString((Map) value, out);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value instanceof Map){
|
if (value instanceof List) {
|
||||||
JSONObject.writeJSONString((Map)value, out);
|
JSONArray.writeJSONString((List) value, out);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(value instanceof List){
|
|
||||||
JSONArray.writeJSONString((List)value, out);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,41 +168,50 @@ public class JSONValue {
|
|||||||
* @param value
|
* @param value
|
||||||
* @return JSON text, or "null" if value is null or it's an NaN or an INF number.
|
* @return JSON text, or "null" if value is null or it's an NaN or an INF number.
|
||||||
*/
|
*/
|
||||||
public static String toJSONString(Object value){
|
public static String toJSONString(Object value) {
|
||||||
if(value == null)
|
if (value == null) {
|
||||||
return "null";
|
return "null";
|
||||||
|
}
|
||||||
|
|
||||||
if(value instanceof String)
|
if (value instanceof String) {
|
||||||
return "\""+escape((String)value)+"\"";
|
return "\"" + escape((String) value) + "\"";
|
||||||
|
}
|
||||||
|
|
||||||
if(value instanceof Double){
|
if (value instanceof Double) {
|
||||||
if(((Double)value).isInfinite() || ((Double)value).isNaN())
|
if (((Double) value).isInfinite() || ((Double) value).isNaN()) {
|
||||||
return "null";
|
return "null";
|
||||||
else
|
} else {
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value instanceof Float) {
|
||||||
|
if (((Float) value).isInfinite() || ((Float) value).isNaN()) {
|
||||||
|
return "null";
|
||||||
|
} else {
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value instanceof Number) {
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value instanceof Float){
|
if (value instanceof Boolean) {
|
||||||
if(((Float)value).isInfinite() || ((Float)value).isNaN())
|
|
||||||
return "null";
|
|
||||||
else
|
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(value instanceof Number)
|
if ((value instanceof JSONAware)) {
|
||||||
return value.toString();
|
return ((JSONAware) value).toJSONString();
|
||||||
|
}
|
||||||
|
|
||||||
if(value instanceof Boolean)
|
if (value instanceof Map) {
|
||||||
return value.toString();
|
return JSONObject.toJSONString((Map) value);
|
||||||
|
}
|
||||||
|
|
||||||
if((value instanceof JSONAware))
|
if (value instanceof List) {
|
||||||
return ((JSONAware)value).toJSONString();
|
return JSONArray.toJSONString((List) value);
|
||||||
|
}
|
||||||
if(value instanceof Map)
|
|
||||||
return JSONObject.toJSONString((Map)value);
|
|
||||||
|
|
||||||
if(value instanceof List)
|
|
||||||
return JSONArray.toJSONString((List)value);
|
|
||||||
|
|
||||||
return value.toString();
|
return value.toString();
|
||||||
}
|
}
|
||||||
@ -212,9 +221,10 @@ public class JSONValue {
|
|||||||
* @param s
|
* @param s
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String escape(String s){
|
public static String escape(String s) {
|
||||||
if(s==null)
|
if (s == null) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
escape(s, sb);
|
escape(s, sb);
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
@ -225,9 +235,9 @@ public class JSONValue {
|
|||||||
* @param sb
|
* @param sb
|
||||||
*/
|
*/
|
||||||
static void escape(String s, StringBuffer sb) {
|
static void escape(String s, StringBuffer sb) {
|
||||||
for(int i=0;i<s.length();i++){
|
for (int i = 0; i < s.length(); i++) {
|
||||||
char ch=s.charAt(i);
|
char ch = s.charAt(i);
|
||||||
switch(ch){
|
switch (ch) {
|
||||||
case '"':
|
case '"':
|
||||||
sb.append("\\\"");
|
sb.append("\\\"");
|
||||||
break;
|
break;
|
||||||
@ -254,19 +264,17 @@ public class JSONValue {
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
//Reference: http://www.unicode.org/versions/Unicode5.1.0/
|
//Reference: http://www.unicode.org/versions/Unicode5.1.0/
|
||||||
if((ch>='\u0000' && ch<='\u001F') || (ch>='\u007F' && ch<='\u009F') || (ch>='\u2000' && ch<='\u20FF')){
|
if ((ch >= '\u0000' && ch <= '\u001F') || (ch >= '\u007F' && ch <= '\u009F') || (ch >= '\u2000' && ch <= '\u20FF')) {
|
||||||
String ss=Integer.toHexString(ch);
|
String ss = Integer.toHexString(ch);
|
||||||
sb.append("\\u");
|
sb.append("\\u");
|
||||||
for(int k=0;k<4-ss.length();k++){
|
for (int k = 0; k < 4 - ss.length(); k++) {
|
||||||
sb.append('0');
|
sb.append('0');
|
||||||
}
|
}
|
||||||
sb.append(ss.toUpperCase());
|
sb.append(ss.toUpperCase());
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
sb.append(ch);
|
sb.append(ch);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}//for
|
}//for
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -106,5 +106,4 @@ public interface ContentHandler {
|
|||||||
* @throws ParseException
|
* @throws ParseException
|
||||||
*/
|
*/
|
||||||
boolean primitive(Object value) throws ParseException, IOException;
|
boolean primitive(Object value) throws ParseException, IOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,31 +14,30 @@ import java.util.Map;
|
|||||||
import org.json.simple.JSONArray;
|
import org.json.simple.JSONArray;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parser for JSON text. Please note that JSONParser is NOT thread-safe.
|
* Parser for JSON text. Please note that JSONParser is NOT thread-safe.
|
||||||
*
|
*
|
||||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||||
*/
|
*/
|
||||||
public class JSONParser {
|
public class JSONParser {
|
||||||
public static final int S_INIT=0;
|
public static final int S_INIT = 0;
|
||||||
public static final int S_IN_FINISHED_VALUE=1;//string,number,boolean,null,object,array
|
public static final int S_IN_FINISHED_VALUE = 1;//string,number,boolean,null,object,array
|
||||||
public static final int S_IN_OBJECT=2;
|
public static final int S_IN_OBJECT = 2;
|
||||||
public static final int S_IN_ARRAY=3;
|
public static final int S_IN_ARRAY = 3;
|
||||||
public static final int S_PASSED_PAIR_KEY=4;
|
public static final int S_PASSED_PAIR_KEY = 4;
|
||||||
public static final int S_IN_PAIR_VALUE=5;
|
public static final int S_IN_PAIR_VALUE = 5;
|
||||||
public static final int S_END=6;
|
public static final int S_END = 6;
|
||||||
public static final int S_IN_ERROR=-1;
|
public static final int S_IN_ERROR = -1;
|
||||||
|
|
||||||
private LinkedList handlerStatusStack;
|
private LinkedList handlerStatusStack;
|
||||||
private Yylex lexer = new Yylex((Reader)null);
|
private Yylex lexer = new Yylex((Reader) null);
|
||||||
private Yytoken token = null;
|
private Yytoken token = null;
|
||||||
private int status = S_INIT;
|
private int status = S_INIT;
|
||||||
|
|
||||||
private int peekStatus(LinkedList statusStack){
|
private int peekStatus(LinkedList statusStack) {
|
||||||
if(statusStack.size()==0)
|
if (statusStack.size() == 0) {
|
||||||
return -1;
|
return -1;
|
||||||
Integer status=(Integer)statusStack.getFirst();
|
}
|
||||||
|
Integer status = (Integer) statusStack.getFirst();
|
||||||
return status.intValue();
|
return status.intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ public class JSONParser {
|
|||||||
* Reset the parser to the initial state without resetting the underlying reader.
|
* Reset the parser to the initial state without resetting the underlying reader.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public void reset(){
|
public void reset() {
|
||||||
token = null;
|
token = null;
|
||||||
status = S_INIT;
|
status = S_INIT;
|
||||||
handlerStatusStack = null;
|
handlerStatusStack = null;
|
||||||
@ -59,7 +58,7 @@ public class JSONParser {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws ParseException
|
* @throws ParseException
|
||||||
*/
|
*/
|
||||||
public void reset(Reader in){
|
public void reset(Reader in) {
|
||||||
lexer.yyreset(in);
|
lexer.yyreset(in);
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
@ -67,20 +66,19 @@ public class JSONParser {
|
|||||||
/**
|
/**
|
||||||
* @return The position of the beginning of the current token.
|
* @return The position of the beginning of the current token.
|
||||||
*/
|
*/
|
||||||
public int getPosition(){
|
public int getPosition() {
|
||||||
return lexer.getPosition();
|
return lexer.getPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object parse(String s) throws ParseException{
|
public Object parse(String s) throws ParseException {
|
||||||
return parse(s, (ContainerFactory)null);
|
return parse(s, (ContainerFactory) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object parse(String s, ContainerFactory containerFactory) throws ParseException{
|
public Object parse(String s, ContainerFactory containerFactory) throws ParseException {
|
||||||
StringReader in=new StringReader(s);
|
StringReader in = new StringReader(s);
|
||||||
try{
|
try {
|
||||||
return parse(in, containerFactory);
|
return parse(in, containerFactory);
|
||||||
}
|
} catch (IOException ie) {
|
||||||
catch(IOException ie){
|
|
||||||
/*
|
/*
|
||||||
* Actually it will never happen.
|
* Actually it will never happen.
|
||||||
*/
|
*/
|
||||||
@ -88,8 +86,8 @@ public class JSONParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object parse(Reader in) throws IOException, ParseException{
|
public Object parse(Reader in) throws IOException, ParseException {
|
||||||
return parse(in, (ContainerFactory)null);
|
return parse(in, (ContainerFactory) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,199 +106,200 @@ public class JSONParser {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws ParseException
|
* @throws ParseException
|
||||||
*/
|
*/
|
||||||
public Object parse(Reader in, ContainerFactory containerFactory) throws IOException, ParseException{
|
public Object parse(Reader in, ContainerFactory containerFactory) throws IOException, ParseException {
|
||||||
reset(in);
|
reset(in);
|
||||||
LinkedList statusStack = new LinkedList();
|
LinkedList statusStack = new LinkedList();
|
||||||
LinkedList valueStack = new LinkedList();
|
LinkedList valueStack = new LinkedList();
|
||||||
|
|
||||||
try{
|
try {
|
||||||
do{
|
do {
|
||||||
nextToken();
|
nextToken();
|
||||||
switch(status){
|
switch (status) {
|
||||||
case S_INIT:
|
case S_INIT:
|
||||||
switch(token.type){
|
switch (token.type) {
|
||||||
case Yytoken.TYPE_VALUE:
|
case Yytoken.TYPE_VALUE:
|
||||||
status=S_IN_FINISHED_VALUE;
|
status = S_IN_FINISHED_VALUE;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
valueStack.addFirst(token.value);
|
valueStack.addFirst(token.value);
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_LEFT_BRACE:
|
case Yytoken.TYPE_LEFT_BRACE:
|
||||||
status=S_IN_OBJECT;
|
status = S_IN_OBJECT;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
valueStack.addFirst(createObjectContainer(containerFactory));
|
valueStack.addFirst(createObjectContainer(containerFactory));
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_LEFT_SQUARE:
|
case Yytoken.TYPE_LEFT_SQUARE:
|
||||||
status=S_IN_ARRAY;
|
status = S_IN_ARRAY;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
valueStack.addFirst(createArrayContainer(containerFactory));
|
valueStack.addFirst(createArrayContainer(containerFactory));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
status=S_IN_ERROR;
|
status = S_IN_ERROR;
|
||||||
}//inner switch
|
}//inner switch
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_IN_FINISHED_VALUE:
|
case S_IN_FINISHED_VALUE:
|
||||||
if(token.type==Yytoken.TYPE_EOF)
|
if (token.type == Yytoken.TYPE_EOF) {
|
||||||
return valueStack.removeFirst();
|
return valueStack.removeFirst();
|
||||||
else
|
} else {
|
||||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||||
|
}
|
||||||
|
|
||||||
case S_IN_OBJECT:
|
case S_IN_OBJECT:
|
||||||
switch(token.type){
|
switch (token.type) {
|
||||||
case Yytoken.TYPE_COMMA:
|
case Yytoken.TYPE_COMMA:
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_VALUE:
|
case Yytoken.TYPE_VALUE:
|
||||||
if(token.value instanceof String){
|
if (token.value instanceof String) {
|
||||||
String key=(String)token.value;
|
String key = (String) token.value;
|
||||||
valueStack.addFirst(key);
|
valueStack.addFirst(key);
|
||||||
status=S_PASSED_PAIR_KEY;
|
status = S_PASSED_PAIR_KEY;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
}
|
} else {
|
||||||
else{
|
status = S_IN_ERROR;
|
||||||
status=S_IN_ERROR;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_RIGHT_BRACE:
|
case Yytoken.TYPE_RIGHT_BRACE:
|
||||||
if(valueStack.size()>1){
|
if (valueStack.size() > 1) {
|
||||||
statusStack.removeFirst();
|
statusStack.removeFirst();
|
||||||
valueStack.removeFirst();
|
valueStack.removeFirst();
|
||||||
status=peekStatus(statusStack);
|
status = peekStatus(statusStack);
|
||||||
}
|
} else {
|
||||||
else{
|
status = S_IN_FINISHED_VALUE;
|
||||||
status=S_IN_FINISHED_VALUE;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
status=S_IN_ERROR;
|
status = S_IN_ERROR;
|
||||||
break;
|
break;
|
||||||
}//inner switch
|
}//inner switch
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_PASSED_PAIR_KEY:
|
case S_PASSED_PAIR_KEY:
|
||||||
switch(token.type){
|
switch (token.type) {
|
||||||
case Yytoken.TYPE_COLON:
|
case Yytoken.TYPE_COLON:
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_VALUE:
|
case Yytoken.TYPE_VALUE:
|
||||||
statusStack.removeFirst();
|
statusStack.removeFirst();
|
||||||
String key=(String)valueStack.removeFirst();
|
String key = (String) valueStack.removeFirst();
|
||||||
Map parent=(Map)valueStack.getFirst();
|
Map parent = (Map) valueStack.getFirst();
|
||||||
parent.put(key,token.value);
|
parent.put(key, token.value);
|
||||||
status=peekStatus(statusStack);
|
status = peekStatus(statusStack);
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_LEFT_SQUARE:
|
case Yytoken.TYPE_LEFT_SQUARE:
|
||||||
statusStack.removeFirst();
|
statusStack.removeFirst();
|
||||||
key=(String)valueStack.removeFirst();
|
key = (String) valueStack.removeFirst();
|
||||||
parent=(Map)valueStack.getFirst();
|
parent = (Map) valueStack.getFirst();
|
||||||
List newArray=createArrayContainer(containerFactory);
|
List newArray = createArrayContainer(containerFactory);
|
||||||
parent.put(key,newArray);
|
parent.put(key, newArray);
|
||||||
status=S_IN_ARRAY;
|
status = S_IN_ARRAY;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
valueStack.addFirst(newArray);
|
valueStack.addFirst(newArray);
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_LEFT_BRACE:
|
case Yytoken.TYPE_LEFT_BRACE:
|
||||||
statusStack.removeFirst();
|
statusStack.removeFirst();
|
||||||
key=(String)valueStack.removeFirst();
|
key = (String) valueStack.removeFirst();
|
||||||
parent=(Map)valueStack.getFirst();
|
parent = (Map) valueStack.getFirst();
|
||||||
Map newObject=createObjectContainer(containerFactory);
|
Map newObject = createObjectContainer(containerFactory);
|
||||||
parent.put(key,newObject);
|
parent.put(key, newObject);
|
||||||
status=S_IN_OBJECT;
|
status = S_IN_OBJECT;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
valueStack.addFirst(newObject);
|
valueStack.addFirst(newObject);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
status=S_IN_ERROR;
|
status = S_IN_ERROR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_IN_ARRAY:
|
case S_IN_ARRAY:
|
||||||
switch(token.type){
|
switch (token.type) {
|
||||||
case Yytoken.TYPE_COMMA:
|
case Yytoken.TYPE_COMMA:
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_VALUE:
|
case Yytoken.TYPE_VALUE:
|
||||||
List val=(List)valueStack.getFirst();
|
List val = (List) valueStack.getFirst();
|
||||||
val.add(token.value);
|
val.add(token.value);
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_RIGHT_SQUARE:
|
case Yytoken.TYPE_RIGHT_SQUARE:
|
||||||
if(valueStack.size()>1){
|
if (valueStack.size() > 1) {
|
||||||
statusStack.removeFirst();
|
statusStack.removeFirst();
|
||||||
valueStack.removeFirst();
|
valueStack.removeFirst();
|
||||||
status=peekStatus(statusStack);
|
status = peekStatus(statusStack);
|
||||||
}
|
} else {
|
||||||
else{
|
status = S_IN_FINISHED_VALUE;
|
||||||
status=S_IN_FINISHED_VALUE;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_LEFT_BRACE:
|
case Yytoken.TYPE_LEFT_BRACE:
|
||||||
val=(List)valueStack.getFirst();
|
val = (List) valueStack.getFirst();
|
||||||
Map newObject=createObjectContainer(containerFactory);
|
Map newObject = createObjectContainer(containerFactory);
|
||||||
val.add(newObject);
|
val.add(newObject);
|
||||||
status=S_IN_OBJECT;
|
status = S_IN_OBJECT;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
valueStack.addFirst(newObject);
|
valueStack.addFirst(newObject);
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_LEFT_SQUARE:
|
case Yytoken.TYPE_LEFT_SQUARE:
|
||||||
val=(List)valueStack.getFirst();
|
val = (List) valueStack.getFirst();
|
||||||
List newArray=createArrayContainer(containerFactory);
|
List newArray = createArrayContainer(containerFactory);
|
||||||
val.add(newArray);
|
val.add(newArray);
|
||||||
status=S_IN_ARRAY;
|
status = S_IN_ARRAY;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
valueStack.addFirst(newArray);
|
valueStack.addFirst(newArray);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
status=S_IN_ERROR;
|
status = S_IN_ERROR;
|
||||||
}//inner switch
|
}//inner switch
|
||||||
break;
|
break;
|
||||||
case S_IN_ERROR:
|
case S_IN_ERROR:
|
||||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||||
}//switch
|
}//switch
|
||||||
if(status==S_IN_ERROR){
|
if (status == S_IN_ERROR) {
|
||||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||||
}
|
}
|
||||||
}while(token.type!=Yytoken.TYPE_EOF);
|
} while (token.type != Yytoken.TYPE_EOF);
|
||||||
}
|
} catch (IOException ie) {
|
||||||
catch(IOException ie){
|
|
||||||
throw ie;
|
throw ie;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void nextToken() throws ParseException, IOException{
|
private void nextToken() throws ParseException, IOException {
|
||||||
token = lexer.yylex();
|
token = lexer.yylex();
|
||||||
if(token == null)
|
if (token == null) {
|
||||||
token = new Yytoken(Yytoken.TYPE_EOF, null);
|
token = new Yytoken(Yytoken.TYPE_EOF, null);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Map createObjectContainer(ContainerFactory containerFactory){
|
private Map createObjectContainer(ContainerFactory containerFactory) {
|
||||||
if(containerFactory == null)
|
if (containerFactory == null) {
|
||||||
return new JSONObject();
|
return new JSONObject();
|
||||||
|
}
|
||||||
Map m = containerFactory.createObjectContainer();
|
Map m = containerFactory.createObjectContainer();
|
||||||
|
|
||||||
if(m == null)
|
if (m == null) {
|
||||||
return new JSONObject();
|
return new JSONObject();
|
||||||
|
}
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List createArrayContainer(ContainerFactory containerFactory){
|
private List createArrayContainer(ContainerFactory containerFactory) {
|
||||||
if(containerFactory == null)
|
if (containerFactory == null) {
|
||||||
return new JSONArray();
|
return new JSONArray();
|
||||||
|
}
|
||||||
List l = containerFactory.creatArrayContainer();
|
List l = containerFactory.creatArrayContainer();
|
||||||
|
|
||||||
if(l == null)
|
if (l == null) {
|
||||||
return new JSONArray();
|
return new JSONArray();
|
||||||
|
}
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parse(String s, ContentHandler contentHandler) throws ParseException{
|
public void parse(String s, ContentHandler contentHandler) throws ParseException {
|
||||||
parse(s, contentHandler, false);
|
parse(s, contentHandler, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parse(String s, ContentHandler contentHandler, boolean isResume) throws ParseException{
|
public void parse(String s, ContentHandler contentHandler, boolean isResume) throws ParseException {
|
||||||
StringReader in=new StringReader(s);
|
StringReader in = new StringReader(s);
|
||||||
try{
|
try {
|
||||||
parse(in, contentHandler, isResume);
|
parse(in, contentHandler, isResume);
|
||||||
}
|
} catch (IOException ie) {
|
||||||
catch(IOException ie){
|
|
||||||
/*
|
/*
|
||||||
* Actually it will never happen.
|
* Actually it will never happen.
|
||||||
*/
|
*/
|
||||||
@ -308,7 +307,7 @@ public class JSONParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void parse(Reader in, ContentHandler contentHandler) throws IOException, ParseException{
|
public void parse(Reader in, ContentHandler contentHandler) throws IOException, ParseException {
|
||||||
parse(in, contentHandler, false);
|
parse(in, contentHandler, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,13 +325,12 @@ public class JSONParser {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws ParseException
|
* @throws ParseException
|
||||||
*/
|
*/
|
||||||
public void parse(Reader in, ContentHandler contentHandler, boolean isResume) throws IOException, ParseException{
|
public void parse(Reader in, ContentHandler contentHandler, boolean isResume) throws IOException, ParseException {
|
||||||
if(!isResume){
|
if (!isResume) {
|
||||||
reset(in);
|
reset(in);
|
||||||
handlerStatusStack = new LinkedList();
|
handlerStatusStack = new LinkedList();
|
||||||
}
|
} else {
|
||||||
else{
|
if (handlerStatusStack == null) {
|
||||||
if(handlerStatusStack == null){
|
|
||||||
isResume = false;
|
isResume = false;
|
||||||
reset(in);
|
reset(in);
|
||||||
handlerStatusStack = new LinkedList();
|
handlerStatusStack = new LinkedList();
|
||||||
@ -341,113 +339,119 @@ public class JSONParser {
|
|||||||
|
|
||||||
LinkedList statusStack = handlerStatusStack;
|
LinkedList statusStack = handlerStatusStack;
|
||||||
|
|
||||||
try{
|
try {
|
||||||
do{
|
do {
|
||||||
switch(status){
|
switch (status) {
|
||||||
case S_INIT:
|
case S_INIT:
|
||||||
contentHandler.startJSON();
|
contentHandler.startJSON();
|
||||||
nextToken();
|
nextToken();
|
||||||
switch(token.type){
|
switch (token.type) {
|
||||||
case Yytoken.TYPE_VALUE:
|
case Yytoken.TYPE_VALUE:
|
||||||
status=S_IN_FINISHED_VALUE;
|
status = S_IN_FINISHED_VALUE;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
if(!contentHandler.primitive(token.value))
|
if (!contentHandler.primitive(token.value)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_LEFT_BRACE:
|
case Yytoken.TYPE_LEFT_BRACE:
|
||||||
status=S_IN_OBJECT;
|
status = S_IN_OBJECT;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
if(!contentHandler.startObject())
|
if (!contentHandler.startObject()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_LEFT_SQUARE:
|
case Yytoken.TYPE_LEFT_SQUARE:
|
||||||
status=S_IN_ARRAY;
|
status = S_IN_ARRAY;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
if(!contentHandler.startArray())
|
if (!contentHandler.startArray()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
status=S_IN_ERROR;
|
status = S_IN_ERROR;
|
||||||
}//inner switch
|
}//inner switch
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_IN_FINISHED_VALUE:
|
case S_IN_FINISHED_VALUE:
|
||||||
nextToken();
|
nextToken();
|
||||||
if(token.type==Yytoken.TYPE_EOF){
|
if (token.type == Yytoken.TYPE_EOF) {
|
||||||
contentHandler.endJSON();
|
contentHandler.endJSON();
|
||||||
status = S_END;
|
status = S_END;
|
||||||
return;
|
return;
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
status = S_IN_ERROR;
|
status = S_IN_ERROR;
|
||||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
case S_IN_OBJECT:
|
case S_IN_OBJECT:
|
||||||
nextToken();
|
nextToken();
|
||||||
switch(token.type){
|
switch (token.type) {
|
||||||
case Yytoken.TYPE_COMMA:
|
case Yytoken.TYPE_COMMA:
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_VALUE:
|
case Yytoken.TYPE_VALUE:
|
||||||
if(token.value instanceof String){
|
if (token.value instanceof String) {
|
||||||
String key=(String)token.value;
|
String key = (String) token.value;
|
||||||
status=S_PASSED_PAIR_KEY;
|
status = S_PASSED_PAIR_KEY;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
if(!contentHandler.startObjectEntry(key))
|
if (!contentHandler.startObjectEntry(key)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else{
|
} else {
|
||||||
status=S_IN_ERROR;
|
status = S_IN_ERROR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_RIGHT_BRACE:
|
case Yytoken.TYPE_RIGHT_BRACE:
|
||||||
if(statusStack.size()>1){
|
if (statusStack.size() > 1) {
|
||||||
statusStack.removeFirst();
|
statusStack.removeFirst();
|
||||||
status=peekStatus(statusStack);
|
status = peekStatus(statusStack);
|
||||||
|
} else {
|
||||||
|
status = S_IN_FINISHED_VALUE;
|
||||||
}
|
}
|
||||||
else{
|
if (!contentHandler.endObject()) {
|
||||||
status=S_IN_FINISHED_VALUE;
|
|
||||||
}
|
|
||||||
if(!contentHandler.endObject())
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
status=S_IN_ERROR;
|
status = S_IN_ERROR;
|
||||||
break;
|
break;
|
||||||
}//inner switch
|
}//inner switch
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_PASSED_PAIR_KEY:
|
case S_PASSED_PAIR_KEY:
|
||||||
nextToken();
|
nextToken();
|
||||||
switch(token.type){
|
switch (token.type) {
|
||||||
case Yytoken.TYPE_COLON:
|
case Yytoken.TYPE_COLON:
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_VALUE:
|
case Yytoken.TYPE_VALUE:
|
||||||
statusStack.removeFirst();
|
statusStack.removeFirst();
|
||||||
status=peekStatus(statusStack);
|
status = peekStatus(statusStack);
|
||||||
if(!contentHandler.primitive(token.value))
|
if (!contentHandler.primitive(token.value)) {
|
||||||
return;
|
return;
|
||||||
if(!contentHandler.endObjectEntry())
|
}
|
||||||
|
if (!contentHandler.endObjectEntry()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_LEFT_SQUARE:
|
case Yytoken.TYPE_LEFT_SQUARE:
|
||||||
statusStack.removeFirst();
|
statusStack.removeFirst();
|
||||||
statusStack.addFirst(new Integer(S_IN_PAIR_VALUE));
|
statusStack.addFirst(new Integer(S_IN_PAIR_VALUE));
|
||||||
status=S_IN_ARRAY;
|
status = S_IN_ARRAY;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
if(!contentHandler.startArray())
|
if (!contentHandler.startArray()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_LEFT_BRACE:
|
case Yytoken.TYPE_LEFT_BRACE:
|
||||||
statusStack.removeFirst();
|
statusStack.removeFirst();
|
||||||
statusStack.addFirst(new Integer(S_IN_PAIR_VALUE));
|
statusStack.addFirst(new Integer(S_IN_PAIR_VALUE));
|
||||||
status=S_IN_OBJECT;
|
status = S_IN_OBJECT;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
if(!contentHandler.startObject())
|
if (!contentHandler.startObject()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
status=S_IN_ERROR;
|
status = S_IN_ERROR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -458,44 +462,48 @@ public class JSONParser {
|
|||||||
*/
|
*/
|
||||||
statusStack.removeFirst();
|
statusStack.removeFirst();
|
||||||
status = peekStatus(statusStack);
|
status = peekStatus(statusStack);
|
||||||
if(!contentHandler.endObjectEntry())
|
if (!contentHandler.endObjectEntry()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case S_IN_ARRAY:
|
case S_IN_ARRAY:
|
||||||
nextToken();
|
nextToken();
|
||||||
switch(token.type){
|
switch (token.type) {
|
||||||
case Yytoken.TYPE_COMMA:
|
case Yytoken.TYPE_COMMA:
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_VALUE:
|
case Yytoken.TYPE_VALUE:
|
||||||
if(!contentHandler.primitive(token.value))
|
if (!contentHandler.primitive(token.value)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_RIGHT_SQUARE:
|
case Yytoken.TYPE_RIGHT_SQUARE:
|
||||||
if(statusStack.size()>1){
|
if (statusStack.size() > 1) {
|
||||||
statusStack.removeFirst();
|
statusStack.removeFirst();
|
||||||
status=peekStatus(statusStack);
|
status = peekStatus(statusStack);
|
||||||
|
} else {
|
||||||
|
status = S_IN_FINISHED_VALUE;
|
||||||
}
|
}
|
||||||
else{
|
if (!contentHandler.endArray()) {
|
||||||
status=S_IN_FINISHED_VALUE;
|
|
||||||
}
|
|
||||||
if(!contentHandler.endArray())
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_LEFT_BRACE:
|
case Yytoken.TYPE_LEFT_BRACE:
|
||||||
status=S_IN_OBJECT;
|
status = S_IN_OBJECT;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
if(!contentHandler.startObject())
|
if (!contentHandler.startObject()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Yytoken.TYPE_LEFT_SQUARE:
|
case Yytoken.TYPE_LEFT_SQUARE:
|
||||||
status=S_IN_ARRAY;
|
status = S_IN_ARRAY;
|
||||||
statusStack.addFirst(new Integer(status));
|
statusStack.addFirst(new Integer(status));
|
||||||
if(!contentHandler.startArray())
|
if (!contentHandler.startArray()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
status=S_IN_ERROR;
|
status = S_IN_ERROR;
|
||||||
}//inner switch
|
}//inner switch
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -505,24 +513,20 @@ public class JSONParser {
|
|||||||
case S_IN_ERROR:
|
case S_IN_ERROR:
|
||||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||||
}//switch
|
}//switch
|
||||||
if(status==S_IN_ERROR){
|
if (status == S_IN_ERROR) {
|
||||||
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
throw new ParseException(getPosition(), ParseException.ERROR_UNEXPECTED_TOKEN, token);
|
||||||
}
|
}
|
||||||
}while(token.type!=Yytoken.TYPE_EOF);
|
} while (token.type != Yytoken.TYPE_EOF);
|
||||||
}
|
} catch (IOException ie) {
|
||||||
catch(IOException ie){
|
|
||||||
status = S_IN_ERROR;
|
status = S_IN_ERROR;
|
||||||
throw ie;
|
throw ie;
|
||||||
}
|
} catch (ParseException pe) {
|
||||||
catch(ParseException pe){
|
|
||||||
status = S_IN_ERROR;
|
status = S_IN_ERROR;
|
||||||
throw pe;
|
throw pe;
|
||||||
}
|
} catch (RuntimeException re) {
|
||||||
catch(RuntimeException re){
|
|
||||||
status = S_IN_ERROR;
|
status = S_IN_ERROR;
|
||||||
throw re;
|
throw re;
|
||||||
}
|
} catch (Error e) {
|
||||||
catch(Error e){
|
|
||||||
status = S_IN_ERROR;
|
status = S_IN_ERROR;
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
@ -8,24 +8,22 @@ package org.json.simple.parser;
|
|||||||
*/
|
*/
|
||||||
public class ParseException extends Exception {
|
public class ParseException extends Exception {
|
||||||
private static final long serialVersionUID = -7880698968187728548L;
|
private static final long serialVersionUID = -7880698968187728548L;
|
||||||
|
|
||||||
public static final int ERROR_UNEXPECTED_CHAR = 0;
|
public static final int ERROR_UNEXPECTED_CHAR = 0;
|
||||||
public static final int ERROR_UNEXPECTED_TOKEN = 1;
|
public static final int ERROR_UNEXPECTED_TOKEN = 1;
|
||||||
public static final int ERROR_UNEXPECTED_EXCEPTION = 2;
|
public static final int ERROR_UNEXPECTED_EXCEPTION = 2;
|
||||||
|
|
||||||
private int errorType;
|
private int errorType;
|
||||||
private Object unexpectedObject;
|
private Object unexpectedObject;
|
||||||
private int position;
|
private int position;
|
||||||
|
|
||||||
public ParseException(int errorType){
|
public ParseException(int errorType) {
|
||||||
this(-1, errorType, null);
|
this(-1, errorType, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParseException(int errorType, Object unexpectedObject){
|
public ParseException(int errorType, Object unexpectedObject) {
|
||||||
this(-1, errorType, unexpectedObject);
|
this(-1, errorType, unexpectedObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParseException(int position, int errorType, Object unexpectedObject){
|
public ParseException(int position, int errorType, Object unexpectedObject) {
|
||||||
this.position = position;
|
this.position = position;
|
||||||
this.errorType = errorType;
|
this.errorType = errorType;
|
||||||
this.unexpectedObject = unexpectedObject;
|
this.unexpectedObject = unexpectedObject;
|
||||||
@ -68,10 +66,10 @@ public class ParseException extends Exception {
|
|||||||
this.unexpectedObject = unexpectedObject;
|
this.unexpectedObject = unexpectedObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString() {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
switch(errorType){
|
switch (errorType) {
|
||||||
case ERROR_UNEXPECTED_CHAR:
|
case ERROR_UNEXPECTED_CHAR:
|
||||||
sb.append("Unexpected character (").append(unexpectedObject).append(") at position ").append(position).append(".");
|
sb.append("Unexpected character (").append(unexpectedObject).append(") at position ").append(position).append(".");
|
||||||
break;
|
break;
|
||||||
|
@ -1,19 +1,14 @@
|
|||||||
/* The following code was generated by JFlex 1.4.2 */
|
/* The following code was generated by JFlex 1.4.2 */
|
||||||
|
|
||||||
package org.json.simple.parser;
|
package org.json.simple.parser;
|
||||||
|
|
||||||
class Yylex {
|
class Yylex {
|
||||||
|
|
||||||
/** This character denotes the end of file */
|
/** This character denotes the end of file */
|
||||||
public static final int YYEOF = -1;
|
public static final int YYEOF = -1;
|
||||||
|
|
||||||
/** initial size of the lookahead buffer */
|
/** initial size of the lookahead buffer */
|
||||||
private static final int ZZ_BUFFERSIZE = 16384;
|
private static final int ZZ_BUFFERSIZE = 16384;
|
||||||
|
|
||||||
/** lexical states */
|
/** lexical states */
|
||||||
public static final int YYINITIAL = 0;
|
public static final int YYINITIAL = 0;
|
||||||
public static final int STRING_BEGIN = 2;
|
public static final int STRING_BEGIN = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
|
* ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
|
||||||
* ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
|
* ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
|
||||||
@ -23,75 +18,70 @@ class Yylex {
|
|||||||
private static final int ZZ_LEXSTATE[] = {
|
private static final int ZZ_LEXSTATE[] = {
|
||||||
0, 0, 1, 1
|
0, 0, 1, 1
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates characters to character classes
|
* Translates characters to character classes
|
||||||
*/
|
*/
|
||||||
private static final String ZZ_CMAP_PACKED =
|
private static final String ZZ_CMAP_PACKED =
|
||||||
"\11\0\1\7\1\7\2\0\1\7\22\0\1\7\1\0\1\11\10\0"+
|
"\11\0\1\7\1\7\2\0\1\7\22\0\1\7\1\0\1\11\10\0"
|
||||||
"\1\6\1\31\1\2\1\4\1\12\12\3\1\32\6\0\4\1\1\5"+
|
+ "\1\6\1\31\1\2\1\4\1\12\12\3\1\32\6\0\4\1\1\5"
|
||||||
"\1\1\24\0\1\27\1\10\1\30\3\0\1\22\1\13\2\1\1\21"+
|
+ "\1\1\24\0\1\27\1\10\1\30\3\0\1\22\1\13\2\1\1\21"
|
||||||
"\1\14\5\0\1\23\1\0\1\15\3\0\1\16\1\24\1\17\1\20"+
|
+ "\1\14\5\0\1\23\1\0\1\15\3\0\1\16\1\24\1\17\1\20"
|
||||||
"\5\0\1\25\1\0\1\26\uff82\0";
|
+ "\5\0\1\25\1\0\1\26\uff82\0";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates characters to character classes
|
* Translates characters to character classes
|
||||||
*/
|
*/
|
||||||
private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
|
private static final char[] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates DFA states to action switch labels.
|
* Translates DFA states to action switch labels.
|
||||||
*/
|
*/
|
||||||
private static final int [] ZZ_ACTION = zzUnpackAction();
|
private static final int[] ZZ_ACTION = zzUnpackAction();
|
||||||
|
|
||||||
private static final String ZZ_ACTION_PACKED_0 =
|
private static final String ZZ_ACTION_PACKED_0 =
|
||||||
"\2\0\2\1\1\2\1\3\1\4\3\1\1\5\1\6"+
|
"\2\0\2\1\1\2\1\3\1\4\3\1\1\5\1\6"
|
||||||
"\1\7\1\10\1\11\1\12\1\13\1\14\1\15\5\0"+
|
+ "\1\7\1\10\1\11\1\12\1\13\1\14\1\15\5\0"
|
||||||
"\1\14\1\16\1\17\1\20\1\21\1\22\1\23\1\24"+
|
+ "\1\14\1\16\1\17\1\20\1\21\1\22\1\23\1\24"
|
||||||
"\1\0\1\25\1\0\1\25\4\0\1\26\1\27\2\0"+
|
+ "\1\0\1\25\1\0\1\25\4\0\1\26\1\27\2\0"
|
||||||
"\1\30";
|
+ "\1\30";
|
||||||
|
|
||||||
private static int [] zzUnpackAction() {
|
private static int[] zzUnpackAction() {
|
||||||
int [] result = new int[45];
|
int[] result = new int[45];
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
|
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int zzUnpackAction(String packed, int offset, int [] result) {
|
private static int zzUnpackAction(String packed, int offset, int[] result) {
|
||||||
int i = 0; /* index in packed string */
|
int i = 0; /* index in packed string */
|
||||||
int j = offset; /* index in unpacked array */
|
int j = offset; /* index in unpacked array */
|
||||||
int l = packed.length();
|
int l = packed.length();
|
||||||
while (i < l) {
|
while (i < l) {
|
||||||
int count = packed.charAt(i++);
|
int count = packed.charAt(i++);
|
||||||
int value = packed.charAt(i++);
|
int value = packed.charAt(i++);
|
||||||
do result[j++] = value; while (--count > 0);
|
do {
|
||||||
|
result[j++] = value;
|
||||||
|
} while (--count > 0);
|
||||||
}
|
}
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translates a state to a row index in the transition table
|
* Translates a state to a row index in the transition table
|
||||||
*/
|
*/
|
||||||
private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
|
private static final int[] ZZ_ROWMAP = zzUnpackRowMap();
|
||||||
|
|
||||||
private static final String ZZ_ROWMAP_PACKED_0 =
|
private static final String ZZ_ROWMAP_PACKED_0 =
|
||||||
"\0\0\0\33\0\66\0\121\0\154\0\207\0\66\0\242"+
|
"\0\0\0\33\0\66\0\121\0\154\0\207\0\66\0\242"
|
||||||
"\0\275\0\330\0\66\0\66\0\66\0\66\0\66\0\66"+
|
+ "\0\275\0\330\0\66\0\66\0\66\0\66\0\66\0\66"
|
||||||
"\0\363\0\u010e\0\66\0\u0129\0\u0144\0\u015f\0\u017a\0\u0195"+
|
+ "\0\363\0\u010e\0\66\0\u0129\0\u0144\0\u015f\0\u017a\0\u0195"
|
||||||
"\0\66\0\66\0\66\0\66\0\66\0\66\0\66\0\66"+
|
+ "\0\66\0\66\0\66\0\66\0\66\0\66\0\66\0\66"
|
||||||
"\0\u01b0\0\u01cb\0\u01e6\0\u01e6\0\u0201\0\u021c\0\u0237\0\u0252"+
|
+ "\0\u01b0\0\u01cb\0\u01e6\0\u01e6\0\u0201\0\u021c\0\u0237\0\u0252"
|
||||||
"\0\66\0\66\0\u026d\0\u0288\0\66";
|
+ "\0\66\0\66\0\u026d\0\u0288\0\66";
|
||||||
|
|
||||||
private static int [] zzUnpackRowMap() {
|
private static int[] zzUnpackRowMap() {
|
||||||
int [] result = new int[45];
|
int[] result = new int[45];
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
|
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int zzUnpackRowMap(String packed, int offset, int [] result) {
|
private static int zzUnpackRowMap(String packed, int offset, int[] result) {
|
||||||
int i = 0; /* index in packed string */
|
int i = 0; /* index in packed string */
|
||||||
int j = offset; /* index in unpacked array */
|
int j = offset; /* index in unpacked array */
|
||||||
int l = packed.length();
|
int l = packed.length();
|
||||||
@ -101,11 +91,10 @@ class Yylex {
|
|||||||
}
|
}
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The transition table of the DFA
|
* The transition table of the DFA
|
||||||
*/
|
*/
|
||||||
private static final int ZZ_TRANS [] = {
|
private static final int ZZ_TRANS[] = {
|
||||||
2, 2, 3, 4, 2, 2, 2, 5, 2, 6,
|
2, 2, 3, 4, 2, 2, 2, 5, 2, 6,
|
||||||
2, 2, 7, 8, 2, 9, 2, 2, 2, 2,
|
2, 2, 7, 8, 2, 9, 2, 2, 2, 2,
|
||||||
2, 10, 11, 12, 13, 14, 15, 16, 16, 16,
|
2, 10, 11, 12, 13, 14, 15, 16, 16, 16,
|
||||||
@ -173,8 +162,7 @@ class Yylex {
|
|||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, 44,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, 44,
|
||||||
-1, 44, -1, 44, -1, -1, -1, -1, -1, 44,
|
-1, 44, -1, 44, -1, -1, -1, -1, -1, 44,
|
||||||
44, -1, -1, -1, -1, 44, 44, -1, -1, -1,
|
44, -1, -1, -1, -1, 44, 44, -1, -1, -1,
|
||||||
-1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1,};
|
||||||
};
|
|
||||||
|
|
||||||
/* error codes */
|
/* error codes */
|
||||||
private static final int ZZ_UNKNOWN_ERROR = 0;
|
private static final int ZZ_UNKNOWN_ERROR = 0;
|
||||||
@ -187,90 +175,75 @@ class Yylex {
|
|||||||
"Error: could not match input",
|
"Error: could not match input",
|
||||||
"Error: pushback value was too large"
|
"Error: pushback value was too large"
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
|
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
|
||||||
*/
|
*/
|
||||||
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
|
private static final int[] ZZ_ATTRIBUTE = zzUnpackAttribute();
|
||||||
|
|
||||||
private static final String ZZ_ATTRIBUTE_PACKED_0 =
|
private static final String ZZ_ATTRIBUTE_PACKED_0 =
|
||||||
"\2\0\1\11\3\1\1\11\3\1\6\11\2\1\1\11"+
|
"\2\0\1\11\3\1\1\11\3\1\6\11\2\1\1\11"
|
||||||
"\5\0\10\11\1\0\1\1\1\0\1\1\4\0\2\11"+
|
+ "\5\0\10\11\1\0\1\1\1\0\1\1\4\0\2\11"
|
||||||
"\2\0\1\11";
|
+ "\2\0\1\11";
|
||||||
|
|
||||||
private static int [] zzUnpackAttribute() {
|
private static int[] zzUnpackAttribute() {
|
||||||
int [] result = new int[45];
|
int[] result = new int[45];
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
|
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int zzUnpackAttribute(String packed, int offset, int [] result) {
|
private static int zzUnpackAttribute(String packed, int offset, int[] result) {
|
||||||
int i = 0; /* index in packed string */
|
int i = 0; /* index in packed string */
|
||||||
int j = offset; /* index in unpacked array */
|
int j = offset; /* index in unpacked array */
|
||||||
int l = packed.length();
|
int l = packed.length();
|
||||||
while (i < l) {
|
while (i < l) {
|
||||||
int count = packed.charAt(i++);
|
int count = packed.charAt(i++);
|
||||||
int value = packed.charAt(i++);
|
int value = packed.charAt(i++);
|
||||||
do result[j++] = value; while (--count > 0);
|
do {
|
||||||
|
result[j++] = value;
|
||||||
|
} while (--count > 0);
|
||||||
}
|
}
|
||||||
return j;
|
return j;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** the input device */
|
/** the input device */
|
||||||
private java.io.Reader zzReader;
|
private java.io.Reader zzReader;
|
||||||
|
|
||||||
/** the current state of the DFA */
|
/** the current state of the DFA */
|
||||||
private int zzState;
|
private int zzState;
|
||||||
|
|
||||||
/** the current lexical state */
|
/** the current lexical state */
|
||||||
private int zzLexicalState = YYINITIAL;
|
private int zzLexicalState = YYINITIAL;
|
||||||
|
|
||||||
/** this buffer contains the current text to be matched and is
|
/** this buffer contains the current text to be matched and is
|
||||||
the source of the yytext() string */
|
the source of the yytext() string */
|
||||||
private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
|
private char zzBuffer[] = new char[ZZ_BUFFERSIZE];
|
||||||
|
|
||||||
/** the textposition at the last accepting state */
|
/** the textposition at the last accepting state */
|
||||||
private int zzMarkedPos;
|
private int zzMarkedPos;
|
||||||
|
|
||||||
/** the current text position in the buffer */
|
/** the current text position in the buffer */
|
||||||
private int zzCurrentPos;
|
private int zzCurrentPos;
|
||||||
|
|
||||||
/** startRead marks the beginning of the yytext() string in the buffer */
|
/** startRead marks the beginning of the yytext() string in the buffer */
|
||||||
private int zzStartRead;
|
private int zzStartRead;
|
||||||
|
|
||||||
/** endRead marks the last character in the buffer, that has been read
|
/** endRead marks the last character in the buffer, that has been read
|
||||||
from input */
|
from input */
|
||||||
private int zzEndRead;
|
private int zzEndRead;
|
||||||
|
|
||||||
/** number of newlines encountered up to the start of the matched text */
|
/** number of newlines encountered up to the start of the matched text */
|
||||||
private int yyline;
|
private int yyline;
|
||||||
|
|
||||||
/** the number of characters up to the start of the matched text */
|
/** the number of characters up to the start of the matched text */
|
||||||
private int yychar;
|
private int yychar;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the number of characters from the last newline up to the start of the
|
* the number of characters from the last newline up to the start of the
|
||||||
* matched text
|
* matched text
|
||||||
*/
|
*/
|
||||||
private int yycolumn;
|
private int yycolumn;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* zzAtBOL == true <=> the scanner is currently at the beginning of a line
|
* zzAtBOL == true <=> the scanner is currently at the beginning of a line
|
||||||
*/
|
*/
|
||||||
private boolean zzAtBOL = true;
|
private boolean zzAtBOL = true;
|
||||||
|
|
||||||
/** zzAtEOF == true <=> the scanner is at the EOF */
|
/** zzAtEOF == true <=> the scanner is at the EOF */
|
||||||
private boolean zzAtEOF;
|
private boolean zzAtEOF;
|
||||||
|
|
||||||
/* user code: */
|
/* user code: */
|
||||||
private StringBuffer sb=new StringBuffer();
|
private StringBuffer sb = new StringBuffer();
|
||||||
|
|
||||||
int getPosition(){
|
int getPosition() {
|
||||||
return yychar;
|
return yychar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new scanner
|
* Creates a new scanner
|
||||||
@ -298,19 +271,20 @@ int getPosition(){
|
|||||||
* @param packed the packed character translation table
|
* @param packed the packed character translation table
|
||||||
* @return the unpacked character translation table
|
* @return the unpacked character translation table
|
||||||
*/
|
*/
|
||||||
private static char [] zzUnpackCMap(String packed) {
|
private static char[] zzUnpackCMap(String packed) {
|
||||||
char [] map = new char[0x10000];
|
char[] map = new char[0x10000];
|
||||||
int i = 0; /* index in packed string */
|
int i = 0; /* index in packed string */
|
||||||
int j = 0; /* index in unpacked array */
|
int j = 0; /* index in unpacked array */
|
||||||
while (i < 90) {
|
while (i < 90) {
|
||||||
int count = packed.charAt(i++);
|
int count = packed.charAt(i++);
|
||||||
char value = packed.charAt(i++);
|
char value = packed.charAt(i++);
|
||||||
do map[j++] = value; while (--count > 0);
|
do {
|
||||||
|
map[j++] = value;
|
||||||
|
} while (--count > 0);
|
||||||
}
|
}
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refills the input buffer.
|
* Refills the input buffer.
|
||||||
*
|
*
|
||||||
@ -324,29 +298,29 @@ int getPosition(){
|
|||||||
if (zzStartRead > 0) {
|
if (zzStartRead > 0) {
|
||||||
System.arraycopy(zzBuffer, zzStartRead,
|
System.arraycopy(zzBuffer, zzStartRead,
|
||||||
zzBuffer, 0,
|
zzBuffer, 0,
|
||||||
zzEndRead-zzStartRead);
|
zzEndRead - zzStartRead);
|
||||||
|
|
||||||
/* translate stored positions */
|
/* translate stored positions */
|
||||||
zzEndRead-= zzStartRead;
|
zzEndRead -= zzStartRead;
|
||||||
zzCurrentPos-= zzStartRead;
|
zzCurrentPos -= zzStartRead;
|
||||||
zzMarkedPos-= zzStartRead;
|
zzMarkedPos -= zzStartRead;
|
||||||
zzStartRead = 0;
|
zzStartRead = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* is the buffer big enough? */
|
/* is the buffer big enough? */
|
||||||
if (zzCurrentPos >= zzBuffer.length) {
|
if (zzCurrentPos >= zzBuffer.length) {
|
||||||
/* if not: blow it up */
|
/* if not: blow it up */
|
||||||
char newBuffer[] = new char[zzCurrentPos*2];
|
char newBuffer[] = new char[zzCurrentPos * 2];
|
||||||
System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
|
System.arraycopy(zzBuffer, 0, newBuffer, 0, zzBuffer.length);
|
||||||
zzBuffer = newBuffer;
|
zzBuffer = newBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* finally: fill the buffer with new input */
|
/* finally: fill the buffer with new input */
|
||||||
int numRead = zzReader.read(zzBuffer, zzEndRead,
|
int numRead = zzReader.read(zzBuffer, zzEndRead,
|
||||||
zzBuffer.length-zzEndRead);
|
zzBuffer.length - zzEndRead);
|
||||||
|
|
||||||
if (numRead > 0) {
|
if (numRead > 0) {
|
||||||
zzEndRead+= numRead;
|
zzEndRead += numRead;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// unlikely but not impossible: read 0 characters, but not at end of stream
|
// unlikely but not impossible: read 0 characters, but not at end of stream
|
||||||
@ -364,7 +338,6 @@ int getPosition(){
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the input stream.
|
* Closes the input stream.
|
||||||
*/
|
*/
|
||||||
@ -372,10 +345,10 @@ int getPosition(){
|
|||||||
zzAtEOF = true; /* indicate end of file */
|
zzAtEOF = true; /* indicate end of file */
|
||||||
zzEndRead = zzStartRead; /* invalidate buffer */
|
zzEndRead = zzStartRead; /* invalidate buffer */
|
||||||
|
|
||||||
if (zzReader != null)
|
if (zzReader != null) {
|
||||||
zzReader.close();
|
zzReader.close();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the scanner to read from a new input stream.
|
* Resets the scanner to read from a new input stream.
|
||||||
@ -397,7 +370,6 @@ int getPosition(){
|
|||||||
zzLexicalState = YYINITIAL;
|
zzLexicalState = YYINITIAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current lexical state.
|
* Returns the current lexical state.
|
||||||
*/
|
*/
|
||||||
@ -405,7 +377,6 @@ int getPosition(){
|
|||||||
return zzLexicalState;
|
return zzLexicalState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enters a new lexical state
|
* Enters a new lexical state
|
||||||
*
|
*
|
||||||
@ -415,15 +386,13 @@ int getPosition(){
|
|||||||
zzLexicalState = newState;
|
zzLexicalState = newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the text matched by the current regular expression.
|
* Returns the text matched by the current regular expression.
|
||||||
*/
|
*/
|
||||||
public final String yytext() {
|
public final String yytext() {
|
||||||
return new String( zzBuffer, zzStartRead, zzMarkedPos-zzStartRead );
|
return new String(zzBuffer, zzStartRead, zzMarkedPos - zzStartRead);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the character at position <tt>pos</tt> from the
|
* Returns the character at position <tt>pos</tt> from the
|
||||||
* matched text.
|
* matched text.
|
||||||
@ -436,18 +405,16 @@ int getPosition(){
|
|||||||
* @return the character at position pos
|
* @return the character at position pos
|
||||||
*/
|
*/
|
||||||
public final char yycharat(int pos) {
|
public final char yycharat(int pos) {
|
||||||
return zzBuffer[zzStartRead+pos];
|
return zzBuffer[zzStartRead + pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the length of the matched text region.
|
* Returns the length of the matched text region.
|
||||||
*/
|
*/
|
||||||
public final int yylength() {
|
public final int yylength() {
|
||||||
return zzMarkedPos-zzStartRead;
|
return zzMarkedPos - zzStartRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reports an error that occured while scanning.
|
* Reports an error that occured while scanning.
|
||||||
*
|
*
|
||||||
@ -466,15 +433,13 @@ int getPosition(){
|
|||||||
String message;
|
String message;
|
||||||
try {
|
try {
|
||||||
message = ZZ_ERROR_MSG[errorCode];
|
message = ZZ_ERROR_MSG[errorCode];
|
||||||
}
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
catch (ArrayIndexOutOfBoundsException e) {
|
|
||||||
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
|
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(message);
|
throw new Error(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pushes the specified amount of characters back into the input stream.
|
* Pushes the specified amount of characters back into the input stream.
|
||||||
*
|
*
|
||||||
@ -484,13 +449,13 @@ int getPosition(){
|
|||||||
* This number must not be greater than yylength()!
|
* This number must not be greater than yylength()!
|
||||||
*/
|
*/
|
||||||
public void yypushback(int number) {
|
public void yypushback(int number) {
|
||||||
if ( number > yylength() )
|
if (number > yylength()) {
|
||||||
zzScanError(ZZ_PUSHBACK_2BIG);
|
zzScanError(ZZ_PUSHBACK_2BIG);
|
||||||
|
}
|
||||||
|
|
||||||
zzMarkedPos -= number;
|
zzMarkedPos -= number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resumes scanning until the next regular expression is matched,
|
* Resumes scanning until the next regular expression is matched,
|
||||||
* the end of input is encountered or an I/O-Error occurs.
|
* the end of input is encountered or an I/O-Error occurs.
|
||||||
@ -506,17 +471,17 @@ int getPosition(){
|
|||||||
int zzCurrentPosL;
|
int zzCurrentPosL;
|
||||||
int zzMarkedPosL;
|
int zzMarkedPosL;
|
||||||
int zzEndReadL = zzEndRead;
|
int zzEndReadL = zzEndRead;
|
||||||
char [] zzBufferL = zzBuffer;
|
char[] zzBufferL = zzBuffer;
|
||||||
char [] zzCMapL = ZZ_CMAP;
|
char[] zzCMapL = ZZ_CMAP;
|
||||||
|
|
||||||
int [] zzTransL = ZZ_TRANS;
|
int[] zzTransL = ZZ_TRANS;
|
||||||
int [] zzRowMapL = ZZ_ROWMAP;
|
int[] zzRowMapL = ZZ_ROWMAP;
|
||||||
int [] zzAttrL = ZZ_ATTRIBUTE;
|
int[] zzAttrL = ZZ_ATTRIBUTE;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
zzMarkedPosL = zzMarkedPos;
|
zzMarkedPosL = zzMarkedPos;
|
||||||
|
|
||||||
yychar+= zzMarkedPosL-zzStartRead;
|
yychar += zzMarkedPosL - zzStartRead;
|
||||||
|
|
||||||
zzAction = -1;
|
zzAction = -1;
|
||||||
|
|
||||||
@ -525,16 +490,16 @@ int getPosition(){
|
|||||||
zzState = ZZ_LEXSTATE[zzLexicalState];
|
zzState = ZZ_LEXSTATE[zzLexicalState];
|
||||||
|
|
||||||
|
|
||||||
zzForAction: {
|
zzForAction:
|
||||||
|
{
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
if (zzCurrentPosL < zzEndReadL)
|
if (zzCurrentPosL < zzEndReadL) {
|
||||||
zzInput = zzBufferL[zzCurrentPosL++];
|
zzInput = zzBufferL[zzCurrentPosL++];
|
||||||
else if (zzAtEOF) {
|
} else if (zzAtEOF) {
|
||||||
zzInput = YYEOF;
|
zzInput = YYEOF;
|
||||||
break zzForAction;
|
break zzForAction;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// store back cached positions
|
// store back cached positions
|
||||||
zzCurrentPos = zzCurrentPosL;
|
zzCurrentPos = zzCurrentPosL;
|
||||||
zzMarkedPos = zzMarkedPosL;
|
zzMarkedPos = zzMarkedPosL;
|
||||||
@ -547,20 +512,23 @@ int getPosition(){
|
|||||||
if (eof) {
|
if (eof) {
|
||||||
zzInput = YYEOF;
|
zzInput = YYEOF;
|
||||||
break zzForAction;
|
break zzForAction;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
zzInput = zzBufferL[zzCurrentPosL++];
|
zzInput = zzBufferL[zzCurrentPosL++];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
|
int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]];
|
||||||
if (zzNext == -1) break zzForAction;
|
if (zzNext == -1) {
|
||||||
|
break zzForAction;
|
||||||
|
}
|
||||||
zzState = zzNext;
|
zzState = zzNext;
|
||||||
|
|
||||||
int zzAttributes = zzAttrL[zzState];
|
int zzAttributes = zzAttrL[zzState];
|
||||||
if ( (zzAttributes & 1) == 1 ) {
|
if ((zzAttributes & 1) == 1) {
|
||||||
zzAction = zzState;
|
zzAction = zzState;
|
||||||
zzMarkedPosL = zzCurrentPosL;
|
zzMarkedPosL = zzCurrentPosL;
|
||||||
if ( (zzAttributes & 8) == 8 ) break zzForAction;
|
if ((zzAttributes & 8) == 8) {
|
||||||
|
break zzForAction;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -570,119 +538,143 @@ int getPosition(){
|
|||||||
zzMarkedPos = zzMarkedPosL;
|
zzMarkedPos = zzMarkedPosL;
|
||||||
|
|
||||||
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
|
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
|
||||||
case 11:
|
case 11: {
|
||||||
{ sb.append(yytext());
|
sb.append(yytext());
|
||||||
}
|
}
|
||||||
case 25: break;
|
case 25:
|
||||||
case 4:
|
break;
|
||||||
{ sb.delete(0, sb.length());yybegin(STRING_BEGIN);
|
case 4: {
|
||||||
|
sb.delete(0, sb.length());
|
||||||
|
yybegin(STRING_BEGIN);
|
||||||
}
|
}
|
||||||
case 26: break;
|
case 26:
|
||||||
case 16:
|
break;
|
||||||
{ sb.append('\b');
|
case 16: {
|
||||||
|
sb.append('\b');
|
||||||
}
|
}
|
||||||
case 27: break;
|
case 27:
|
||||||
case 6:
|
break;
|
||||||
{ return new Yytoken(Yytoken.TYPE_RIGHT_BRACE,null);
|
case 6: {
|
||||||
|
return new Yytoken(Yytoken.TYPE_RIGHT_BRACE, null);
|
||||||
}
|
}
|
||||||
case 28: break;
|
case 28:
|
||||||
case 23:
|
break;
|
||||||
{ Boolean val=Boolean.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);
|
case 23: {
|
||||||
|
Boolean val = Boolean.valueOf(yytext());
|
||||||
|
return new Yytoken(Yytoken.TYPE_VALUE, val);
|
||||||
}
|
}
|
||||||
case 29: break;
|
case 29:
|
||||||
case 22:
|
break;
|
||||||
{ return new Yytoken(Yytoken.TYPE_VALUE, null);
|
case 22: {
|
||||||
|
return new Yytoken(Yytoken.TYPE_VALUE, null);
|
||||||
}
|
}
|
||||||
case 30: break;
|
case 30:
|
||||||
case 13:
|
break;
|
||||||
{ yybegin(YYINITIAL);return new Yytoken(Yytoken.TYPE_VALUE, sb.toString());
|
case 13: {
|
||||||
|
yybegin(YYINITIAL);
|
||||||
|
return new Yytoken(Yytoken.TYPE_VALUE, sb.toString());
|
||||||
}
|
}
|
||||||
case 31: break;
|
case 31:
|
||||||
case 12:
|
break;
|
||||||
{ sb.append('\\');
|
case 12: {
|
||||||
|
sb.append('\\');
|
||||||
}
|
}
|
||||||
case 32: break;
|
case 32:
|
||||||
case 21:
|
break;
|
||||||
{ Double val=Double.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);
|
case 21: {
|
||||||
|
Double val = Double.valueOf(yytext());
|
||||||
|
return new Yytoken(Yytoken.TYPE_VALUE, val);
|
||||||
}
|
}
|
||||||
case 33: break;
|
case 33:
|
||||||
case 1:
|
break;
|
||||||
{ throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_CHAR, new Character(yycharat(0)));
|
case 1: {
|
||||||
|
throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_CHAR, new Character(yycharat(0)));
|
||||||
}
|
}
|
||||||
case 34: break;
|
case 34:
|
||||||
case 8:
|
break;
|
||||||
{ return new Yytoken(Yytoken.TYPE_RIGHT_SQUARE,null);
|
case 8: {
|
||||||
|
return new Yytoken(Yytoken.TYPE_RIGHT_SQUARE, null);
|
||||||
}
|
}
|
||||||
case 35: break;
|
case 35:
|
||||||
case 19:
|
break;
|
||||||
{ sb.append('\r');
|
case 19: {
|
||||||
|
sb.append('\r');
|
||||||
}
|
}
|
||||||
case 36: break;
|
case 36:
|
||||||
case 15:
|
break;
|
||||||
{ sb.append('/');
|
case 15: {
|
||||||
|
sb.append('/');
|
||||||
}
|
}
|
||||||
case 37: break;
|
case 37:
|
||||||
case 10:
|
break;
|
||||||
{ return new Yytoken(Yytoken.TYPE_COLON,null);
|
case 10: {
|
||||||
|
return new Yytoken(Yytoken.TYPE_COLON, null);
|
||||||
}
|
}
|
||||||
case 38: break;
|
case 38:
|
||||||
case 14:
|
break;
|
||||||
{ sb.append('"');
|
case 14: {
|
||||||
|
sb.append('"');
|
||||||
}
|
}
|
||||||
case 39: break;
|
case 39:
|
||||||
case 5:
|
break;
|
||||||
{ return new Yytoken(Yytoken.TYPE_LEFT_BRACE,null);
|
case 5: {
|
||||||
|
return new Yytoken(Yytoken.TYPE_LEFT_BRACE, null);
|
||||||
}
|
}
|
||||||
case 40: break;
|
case 40:
|
||||||
case 17:
|
break;
|
||||||
{ sb.append('\f');
|
case 17: {
|
||||||
|
sb.append('\f');
|
||||||
}
|
}
|
||||||
case 41: break;
|
case 41:
|
||||||
case 24:
|
break;
|
||||||
{ try{
|
case 24: {
|
||||||
int ch=Integer.parseInt(yytext().substring(2),16);
|
try {
|
||||||
sb.append((char)ch);
|
int ch = Integer.parseInt(yytext().substring(2), 16);
|
||||||
}
|
sb.append((char) ch);
|
||||||
catch(Exception e){
|
} catch (Exception e) {
|
||||||
throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_EXCEPTION, e);
|
throw new ParseException(yychar, ParseException.ERROR_UNEXPECTED_EXCEPTION, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 42: break;
|
case 42:
|
||||||
case 20:
|
break;
|
||||||
{ sb.append('\t');
|
case 20: {
|
||||||
|
sb.append('\t');
|
||||||
}
|
}
|
||||||
case 43: break;
|
case 43:
|
||||||
case 7:
|
break;
|
||||||
{ return new Yytoken(Yytoken.TYPE_LEFT_SQUARE,null);
|
case 7: {
|
||||||
|
return new Yytoken(Yytoken.TYPE_LEFT_SQUARE, null);
|
||||||
}
|
}
|
||||||
case 44: break;
|
case 44:
|
||||||
case 2:
|
break;
|
||||||
{ Long val=Long.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);
|
case 2: {
|
||||||
|
Long val = Long.valueOf(yytext());
|
||||||
|
return new Yytoken(Yytoken.TYPE_VALUE, val);
|
||||||
}
|
}
|
||||||
case 45: break;
|
case 45:
|
||||||
case 18:
|
break;
|
||||||
{ sb.append('\n');
|
case 18: {
|
||||||
|
sb.append('\n');
|
||||||
}
|
}
|
||||||
case 46: break;
|
case 46:
|
||||||
case 9:
|
break;
|
||||||
{ return new Yytoken(Yytoken.TYPE_COMMA,null);
|
case 9: {
|
||||||
|
return new Yytoken(Yytoken.TYPE_COMMA, null);
|
||||||
}
|
}
|
||||||
case 47: break;
|
case 47:
|
||||||
case 3:
|
break;
|
||||||
{
|
case 3: {
|
||||||
}
|
}
|
||||||
case 48: break;
|
case 48:
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
|
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
|
||||||
zzAtEOF = true;
|
zzAtEOF = true;
|
||||||
return null;
|
return null;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
zzScanError(ZZ_NO_MATCH);
|
zzScanError(ZZ_NO_MATCH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,26 +8,25 @@ package org.json.simple.parser;
|
|||||||
* @author FangYidong<fangyidong@yahoo.com.cn>
|
* @author FangYidong<fangyidong@yahoo.com.cn>
|
||||||
*/
|
*/
|
||||||
public class Yytoken {
|
public class Yytoken {
|
||||||
public static final int TYPE_VALUE=0;//JSON primitive value: string,number,boolean,null
|
public static final int TYPE_VALUE = 0;//JSON primitive value: string,number,boolean,null
|
||||||
public static final int TYPE_LEFT_BRACE=1;
|
public static final int TYPE_LEFT_BRACE = 1;
|
||||||
public static final int TYPE_RIGHT_BRACE=2;
|
public static final int TYPE_RIGHT_BRACE = 2;
|
||||||
public static final int TYPE_LEFT_SQUARE=3;
|
public static final int TYPE_LEFT_SQUARE = 3;
|
||||||
public static final int TYPE_RIGHT_SQUARE=4;
|
public static final int TYPE_RIGHT_SQUARE = 4;
|
||||||
public static final int TYPE_COMMA=5;
|
public static final int TYPE_COMMA = 5;
|
||||||
public static final int TYPE_COLON=6;
|
public static final int TYPE_COLON = 6;
|
||||||
public static final int TYPE_EOF=-1;//end of file
|
public static final int TYPE_EOF = -1;//end of file
|
||||||
|
public int type = 0;
|
||||||
|
public Object value = null;
|
||||||
|
|
||||||
public int type=0;
|
public Yytoken(int type, Object value) {
|
||||||
public Object value=null;
|
this.type = type;
|
||||||
|
this.value = value;
|
||||||
public Yytoken(int type,Object value){
|
|
||||||
this.type=type;
|
|
||||||
this.value=value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(){
|
public String toString() {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
switch(type){
|
switch (type) {
|
||||||
case TYPE_VALUE:
|
case TYPE_VALUE:
|
||||||
sb.append("VALUE(").append(value).append(")");
|
sb.append("VALUE(").append(value).append(")");
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user