diff options
Diffstat (limited to 'src/org')
-rw-r--r-- | src/org/json/simple/ItemList.java | 158 | ||||
-rw-r--r-- | src/org/json/simple/JSONArray.java | 390 | ||||
-rw-r--r-- | src/org/json/simple/JSONAware.java | 14 | ||||
-rw-r--r-- | src/org/json/simple/JSONObject.java | 143 | ||||
-rw-r--r-- | src/org/json/simple/JSONStreamAware.java | 18 | ||||
-rw-r--r-- | src/org/json/simple/JSONValue.java | 317 | ||||
-rw-r--r-- | src/org/json/simple/jsonsimple.gwt.xml | 4 | ||||
-rw-r--r-- | src/org/json/simple/parser/ContainerFactory.java | 26 | ||||
-rw-r--r-- | src/org/json/simple/parser/ContentHandler.java | 110 | ||||
-rw-r--r-- | src/org/json/simple/parser/JSONParser.java | 544 | ||||
-rw-r--r-- | src/org/json/simple/parser/ParseException.java | 92 | ||||
-rw-r--r-- | src/org/json/simple/parser/Yylex.java | 625 | ||||
-rw-r--r-- | src/org/json/simple/parser/Yytoken.java | 60 |
13 files changed, 2501 insertions, 0 deletions
diff --git a/src/org/json/simple/ItemList.java b/src/org/json/simple/ItemList.java new file mode 100644 index 0000000..fc98549 --- /dev/null +++ b/src/org/json/simple/ItemList.java | |||
@@ -0,0 +1,158 @@ | |||
1 | /* | ||
2 | * $Id: ItemList.java,v 1.1 2006/04/15 14:10:48 platform Exp $ | ||
3 | * Created on 2006-3-24 | ||
4 | */ | ||
5 | package org.json.simple; | ||
6 | |||
7 | import java.util.ArrayList; | ||
8 | import java.util.List; | ||
9 | import java.util.StringTokenizer; | ||
10 | |||
11 | /** | ||
12 | * |a:b:c| => |a|,|b|,|c| |:| => ||,|| |a:| => |a|,|| | ||
13 | * | ||
14 | * @author FangYidong<fangyidong@yahoo.com.cn> | ||
15 | */ | ||
16 | public class ItemList { | ||
17 | private String sp = ","; | ||
18 | @SuppressWarnings("rawtypes") | ||
19 | List items = new ArrayList(); | ||
20 | |||
21 | public ItemList() { | ||
22 | } | ||
23 | |||
24 | public ItemList(final String s) { | ||
25 | this.split(s, this.sp, this.items); | ||
26 | } | ||
27 | |||
28 | public ItemList(final String s, final String sp) { | ||
29 | this.sp = s; | ||
30 | this.split(s, sp, this.items); | ||
31 | } | ||
32 | |||
33 | public ItemList(final String s, final String sp, final boolean isMultiToken) { | ||
34 | this.split(s, sp, this.items, isMultiToken); | ||
35 | } | ||
36 | |||
37 | @SuppressWarnings("rawtypes") | ||
38 | public List getItems() { | ||
39 | return this.items; | ||
40 | } | ||
41 | |||
42 | public String[] getArray() { | ||
43 | return (String[]) this.items.toArray(); | ||
44 | } | ||
45 | |||
46 | @SuppressWarnings({ "rawtypes", "unchecked" }) | ||
47 | public void split(final String s, final String sp, final List append, final boolean isMultiToken) { | ||
48 | if ((s == null) || (sp == null)) { | ||
49 | return; | ||
50 | } | ||
51 | if (isMultiToken) { | ||
52 | final StringTokenizer tokens = new StringTokenizer(s, sp); | ||
53 | while (tokens.hasMoreTokens()) { | ||
54 | append.add(tokens.nextToken().trim()); | ||
55 | } | ||
56 | } else { | ||
57 | this.split(s, sp, append); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | @SuppressWarnings({ "rawtypes", "unchecked" }) | ||
62 | public void split(final String s, final String sp, final List append) { | ||
63 | if ((s == null) || (sp == null)) { | ||
64 | return; | ||
65 | } | ||
66 | int pos = 0; | ||
67 | int prevPos = 0; | ||
68 | do { | ||
69 | prevPos = pos; | ||
70 | pos = s.indexOf(sp, pos); | ||
71 | if (pos == -1) { | ||
72 | break; | ||
73 | } | ||
74 | append.add(s.substring(prevPos, pos).trim()); | ||
75 | pos += sp.length(); | ||
76 | } while (pos != -1); | ||
77 | append.add(s.substring(prevPos).trim()); | ||
78 | } | ||
79 | |||
80 | public void setSP(final String sp) { | ||
81 | this.sp = sp; | ||
82 | } | ||
83 | |||
84 | @SuppressWarnings("unchecked") | ||
85 | public void add(final int i, final String item) { | ||
86 | if (item == null) { | ||
87 | return; | ||
88 | } | ||
89 | this.items.add(i, item.trim()); | ||
90 | } | ||
91 | |||
92 | @SuppressWarnings("unchecked") | ||
93 | public void add(final String item) { | ||
94 | if (item == null) { | ||
95 | return; | ||
96 | } | ||
97 | this.items.add(item.trim()); | ||
98 | } | ||
99 | |||
100 | @SuppressWarnings("unchecked") | ||
101 | public void addAll(final ItemList list) { | ||
102 | this.items.addAll(list.items); | ||
103 | } | ||
104 | |||
105 | public void addAll(final String s) { | ||
106 | this.split(s, this.sp, this.items); | ||
107 | } | ||
108 | |||
109 | public void addAll(final String s, final String sp) { | ||
110 | this.split(s, sp, this.items); | ||
111 | } | ||
112 | |||
113 | public void addAll(final String s, final String sp, final boolean isMultiToken) { | ||
114 | this.split(s, sp, this.items, isMultiToken); | ||
115 | } | ||
116 | |||
117 | /** | ||
118 | * @param i | ||
119 | * 0-based | ||
120 | * @return | ||
121 | */ | ||
122 | public String get(final int i) { | ||
123 | return (String) this.items.get(i); | ||
124 | } | ||
125 | |||
126 | public int size() { | ||
127 | return this.items.size(); | ||
128 | } | ||
129 | |||
130 | @Override | ||
131 | public String toString() { | ||
132 | return this.toString(this.sp); | ||
133 | } | ||
134 | |||
135 | public String toString(final String sp) { | ||
136 | final StringBuffer sb = new StringBuffer(); | ||
137 | |||
138 | for (int i = 0; i < this.items.size(); i++) { | ||
139 | if (i == 0) { | ||
140 | sb.append(this.items.get(i)); | ||
141 | } else { | ||
142 | sb.append(sp); | ||
143 | sb.append(this.items.get(i)); | ||
144 | } | ||
145 | } | ||
146 | return sb.toString(); | ||
147 | |||
148 | } | ||
149 | |||
150 | public void clear() { | ||
151 | this.items.clear(); | ||
152 | } | ||
153 | |||
154 | public void reset() { | ||
155 | this.sp = ","; | ||
156 | this.items.clear(); | ||
157 | } | ||
158 | } | ||
diff --git a/src/org/json/simple/JSONArray.java b/src/org/json/simple/JSONArray.java new file mode 100644 index 0000000..e2c7042 --- /dev/null +++ b/src/org/json/simple/JSONArray.java | |||
@@ -0,0 +1,390 @@ | |||
1 | /* | ||
2 | * $Id: JSONArray.java,v 1.1 2006/04/15 14:10:48 platform Exp $ | ||
3 | * Created on 2006-4-10 | ||
4 | */ | ||
5 | package org.json.simple; | ||
6 | |||
7 | import java.io.IOException; | ||
8 | import java.util.ArrayList; | ||
9 | import java.util.Collection; | ||
10 | import java.util.Iterator; | ||
11 | |||
12 | import rejava.io.StringWriter; | ||
13 | import rejava.io.Writer; | ||
14 | |||
15 | /** | ||
16 | * A JSON array. JSONObject supports java.util.List interface. | ||
17 | * | ||
18 | * @author FangYidong<fangyidong@yahoo.com.cn> | ||
19 | */ | ||
20 | public class JSONArray extends ArrayList<Object> implements JSONAware, JSONStreamAware { | ||
21 | private static final long serialVersionUID = 3957988303675231981L; | ||
22 | |||
23 | /** | ||
24 | * Constructs an empty JSONArray. | ||
25 | */ | ||
26 | public JSONArray() { | ||
27 | super(); | ||
28 | } | ||
29 | |||
30 | /** | ||
31 | * Constructs a JSONArray containing the elements of the specified | ||
32 | * collection, in the order they are returned by the collection's iterator. | ||
33 | * | ||
34 | * @param c | ||
35 | * the collection whose elements are to be placed into this | ||
36 | * JSONArray | ||
37 | */ | ||
38 | public JSONArray(final Collection<?> c) { | ||
39 | super(c); | ||
40 | } | ||
41 | |||
42 | /** | ||
43 | * Encode a list into JSON text and write it to out. If this list is also a | ||
44 | * JSONStreamAware or a JSONAware, JSONStreamAware and JSONAware specific | ||
45 | * behaviours will be ignored at this top level. | ||
46 | * | ||
47 | * @see org.json.simple.JSONValue#writeJSONString(Object, Writer) | ||
48 | * | ||
49 | * @param collection | ||
50 | * @param out | ||
51 | */ | ||
52 | public static void writeJSONString(final Collection<?> collection, final Writer out) throws IOException { | ||
53 | if (collection == null) { | ||
54 | out.write("null"); | ||
55 | return; | ||
56 | } | ||
57 | |||
58 | boolean first = true; | ||