picrate 0.0.2-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +47 -0
- data/.mvn/extensions.xml +9 -0
- data/.mvn/wrapper/maven-wrapper.properties +1 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +4 -0
- data/LICENSE.md +165 -0
- data/README.md +51 -0
- data/Rakefile +59 -0
- data/bin/picrate +8 -0
- data/docs/.gitignore +6 -0
- data/docs/_config.yml +30 -0
- data/docs/_includes/footer.html +38 -0
- data/docs/_includes/head.html +16 -0
- data/docs/_includes/header.html +27 -0
- data/docs/_includes/icon-github.html +1 -0
- data/docs/_includes/icon-github.svg +1 -0
- data/docs/_includes/icon-twitter.html +1 -0
- data/docs/_includes/icon-twitter.svg +1 -0
- data/docs/_includes/navigation.html +24 -0
- data/docs/_layouts/default.html +20 -0
- data/docs/_layouts/page.html +14 -0
- data/docs/_layouts/post.html +15 -0
- data/docs/_posts/2018-05-06-getting_started.md +8 -0
- data/docs/_posts/2018-05-06-install_jruby.md +35 -0
- data/docs/_sass/_base.scss +206 -0
- data/docs/_sass/_layout.scss +242 -0
- data/docs/_sass/_syntax-highlighting.scss +71 -0
- data/docs/about.md +10 -0
- data/docs/css/main.scss +38 -0
- data/docs/favicon.ico +0 -0
- data/docs/feed.xml +30 -0
- data/docs/index.html +38 -0
- data/lib/picrate.rb +10 -0
- data/lib/picrate/app.rb +187 -0
- data/lib/picrate/creators/sketch_class.rb +57 -0
- data/lib/picrate/creators/sketch_factory.rb +12 -0
- data/lib/picrate/creators/sketch_writer.rb +21 -0
- data/lib/picrate/helper_methods.rb +214 -0
- data/lib/picrate/helpers/numeric.rb +9 -0
- data/lib/picrate/library.rb +69 -0
- data/lib/picrate/library_loader.rb +53 -0
- data/lib/picrate/native_folder.rb +35 -0
- data/lib/picrate/native_loader.rb +27 -0
- data/lib/picrate/runner.rb +81 -0
- data/lib/picrate/version.rb +4 -0
- data/library/boids/boids.rb +209 -0
- data/library/chooser/chooser.rb +19 -0
- data/library/control_panel/control_panel.rb +182 -0
- data/library/library_proxy/README.md +99 -0
- data/library/library_proxy/library_proxy.rb +14 -0
- data/library/slider/slider.rb +42 -0
- data/library/vector_utils/vector_utils.rb +69 -0
- data/library/video_event/video_event.rb +3 -0
- data/license.txt +508 -0
- data/picrate.gemspec +35 -0
- data/pom.rb +122 -0
- data/pom.xml +214 -0
- data/src/main/java/japplemenubar/JAppleMenuBar.java +88 -0
- data/src/main/java/japplemenubar/libjAppleMenuBar.jnilib +0 -0
- data/src/main/java/monkstone/ColorUtil.java +115 -0
- data/src/main/java/monkstone/MathToolModule.java +236 -0
- data/src/main/java/monkstone/PicrateLibrary.java +47 -0
- data/src/main/java/monkstone/core/LibraryProxy.java +127 -0
- data/src/main/java/monkstone/fastmath/Deglut.java +122 -0
- data/src/main/java/monkstone/fastmath/package-info.java +6 -0
- data/src/main/java/monkstone/filechooser/Chooser.java +48 -0
- data/src/main/java/monkstone/noise/SimplexNoise.java +465 -0
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +168 -0
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +182 -0
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +149 -0
- data/src/main/java/monkstone/slider/SimpleSlider.java +196 -0
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +163 -0
- data/src/main/java/monkstone/slider/Slider.java +67 -0
- data/src/main/java/monkstone/slider/SliderBar.java +277 -0
- data/src/main/java/monkstone/slider/SliderGroup.java +78 -0
- data/src/main/java/monkstone/slider/WheelHandler.java +35 -0
- data/src/main/java/monkstone/vecmath/AppRender.java +87 -0
- data/src/main/java/monkstone/vecmath/JRender.java +56 -0
- data/src/main/java/monkstone/vecmath/ShapeRender.java +87 -0
- data/src/main/java/monkstone/vecmath/package-info.java +20 -0
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +757 -0
- data/src/main/java/monkstone/vecmath/vec2/package-info.java +6 -0
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +727 -0
- data/src/main/java/monkstone/vecmath/vec3/package-info.java +6 -0
- data/src/main/java/monkstone/videoevent/VideoInterface.java +42 -0
- data/src/main/java/monkstone/videoevent/package-info.java +20 -0
- data/src/main/java/processing/awt/PGraphicsJava2D.java +3098 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +401 -0
- data/src/main/java/processing/awt/PSurfaceAWT.java +1660 -0
- data/src/main/java/processing/core/PApplet.java +17647 -0
- data/src/main/java/processing/core/PConstants.java +1033 -0
- data/src/main/java/processing/core/PFont.java +1250 -0
- data/src/main/java/processing/core/PGraphics.java +9614 -0
- data/src/main/java/processing/core/PImage.java +3608 -0
- data/src/main/java/processing/core/PMatrix.java +347 -0
- data/src/main/java/processing/core/PMatrix2D.java +694 -0
- data/src/main/java/processing/core/PMatrix3D.java +1153 -0
- data/src/main/java/processing/core/PShape.java +4332 -0
- data/src/main/java/processing/core/PShapeOBJ.java +544 -0
- data/src/main/java/processing/core/PShapeSVG.java +1987 -0
- data/src/main/java/processing/core/PStyle.java +208 -0
- data/src/main/java/processing/core/PSurface.java +242 -0
- data/src/main/java/processing/core/PSurfaceNone.java +479 -0
- data/src/main/java/processing/core/PVector.java +1140 -0
- data/src/main/java/processing/data/FloatDict.java +829 -0
- data/src/main/java/processing/data/FloatList.java +912 -0
- data/src/main/java/processing/data/IntDict.java +796 -0
- data/src/main/java/processing/data/IntList.java +913 -0
- data/src/main/java/processing/data/JSONArray.java +1260 -0
- data/src/main/java/processing/data/JSONObject.java +2282 -0
- data/src/main/java/processing/data/JSONTokener.java +435 -0
- data/src/main/java/processing/data/Sort.java +46 -0
- data/src/main/java/processing/data/StringDict.java +601 -0
- data/src/main/java/processing/data/StringList.java +775 -0
- data/src/main/java/processing/data/Table.java +4923 -0
- data/src/main/java/processing/data/TableRow.java +198 -0
- data/src/main/java/processing/data/XML.java +1149 -0
- data/src/main/java/processing/event/Event.java +108 -0
- data/src/main/java/processing/event/KeyEvent.java +70 -0
- data/src/main/java/processing/event/MouseEvent.java +149 -0
- data/src/main/java/processing/event/TouchEvent.java +57 -0
- data/src/main/java/processing/javafx/PGraphicsFX2D.java +354 -0
- data/src/main/java/processing/opengl/FontTexture.java +379 -0
- data/src/main/java/processing/opengl/FrameBuffer.java +503 -0
- data/src/main/java/processing/opengl/LinePath.java +623 -0
- data/src/main/java/processing/opengl/LineStroker.java +685 -0
- data/src/main/java/processing/opengl/PGL.java +3366 -0
- data/src/main/java/processing/opengl/PGraphics2D.java +615 -0
- data/src/main/java/processing/opengl/PGraphics3D.java +281 -0
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +13634 -0
- data/src/main/java/processing/opengl/PJOGL.java +1966 -0
- data/src/main/java/processing/opengl/PShader.java +1478 -0
- data/src/main/java/processing/opengl/PShapeOpenGL.java +5234 -0
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1315 -0
- data/src/main/java/processing/opengl/Texture.java +1670 -0
- data/src/main/java/processing/opengl/VertexBuffer.java +88 -0
- data/src/main/java/processing/opengl/cursors/arrow.png +0 -0
- data/src/main/java/processing/opengl/cursors/cross.png +0 -0
- data/src/main/java/processing/opengl/cursors/hand.png +0 -0
- data/src/main/java/processing/opengl/cursors/license.txt +27 -0
- data/src/main/java/processing/opengl/cursors/move.png +0 -0
- data/src/main/java/processing/opengl/cursors/text.png +0 -0
- data/src/main/java/processing/opengl/cursors/wait.png +0 -0
- data/src/main/java/processing/opengl/shaders/ColorFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/ColorVert.glsl +34 -0
- data/src/main/java/processing/opengl/shaders/LightFrag.glsl +33 -0
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +154 -0
- data/src/main/java/processing/opengl/shaders/LightVert.glsl +151 -0
- data/src/main/java/processing/opengl/shaders/LineFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/LineVert.glsl +100 -0
- data/src/main/java/processing/opengl/shaders/MaskFrag.glsl +40 -0
- data/src/main/java/processing/opengl/shaders/PointFrag.glsl +32 -0
- data/src/main/java/processing/opengl/shaders/PointVert.glsl +56 -0
- data/src/main/java/processing/opengl/shaders/TexFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightFrag.glsl +37 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +160 -0
- data/src/main/java/processing/opengl/shaders/TexLightVert.glsl +157 -0
- data/src/main/java/processing/opengl/shaders/TexVert.glsl +38 -0
- data/src/main/resources/icon/icon-1024.png +0 -0
- data/src/main/resources/icon/icon-128.png +0 -0
- data/src/main/resources/icon/icon-16.png +0 -0
- data/src/main/resources/icon/icon-256.png +0 -0
- data/src/main/resources/icon/icon-32.png +0 -0
- data/src/main/resources/icon/icon-48.png +0 -0
- data/src/main/resources/icon/icon-512.png +0 -0
- data/src/main/resources/icon/icon-64.png +0 -0
- data/src/main/resources/license.txt +508 -0
- data/test/create_test.rb +68 -0
- data/test/deglut_spec_test.rb +24 -0
- data/test/helper_methods_test.rb +58 -0
- data/test/math_tool_test.rb +75 -0
- data/test/respond_to_test.rb +215 -0
- data/test/sketches/key_event.rb +37 -0
- data/test/sketches/library/my_library/my_library.rb +32 -0
- data/test/test_helper.rb +3 -0
- data/test/vecmath_spec_test.rb +522 -0
- data/vendors/Rakefile +127 -0
- metadata +289 -0
@@ -0,0 +1,435 @@
|
|
1
|
+
package processing.data;
|
2
|
+
|
3
|
+
import java.io.BufferedReader;
|
4
|
+
import java.io.IOException;
|
5
|
+
import java.io.InputStream;
|
6
|
+
import java.io.InputStreamReader;
|
7
|
+
import java.io.Reader;
|
8
|
+
import java.io.StringReader;
|
9
|
+
|
10
|
+
/*
|
11
|
+
Copyright (c) 2002 JSON.org
|
12
|
+
|
13
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
14
|
+
of this software and associated documentation files (the "Software"), to deal
|
15
|
+
in the Software without restriction, including without limitation the rights
|
16
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
17
|
+
copies of the Software, and to permit persons to whom the Software is
|
18
|
+
furnished to do so, subject to the following conditions:
|
19
|
+
|
20
|
+
The above copyright notice and this permission notice shall be included in all
|
21
|
+
copies or substantial portions of the Software.
|
22
|
+
|
23
|
+
The Software shall be used for Good, not Evil.
|
24
|
+
|
25
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
26
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
27
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
28
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
29
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
30
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
31
|
+
SOFTWARE.
|
32
|
+
*/
|
33
|
+
|
34
|
+
/**
|
35
|
+
* A JSONTokener takes a source string and extracts characters and tokens from
|
36
|
+
* it. It is used by the JSONObject and JSONArray constructors to parse
|
37
|
+
* JSON source strings.
|
38
|
+
* @author JSON.org
|
39
|
+
* @version 2012-02-16
|
40
|
+
*/
|
41
|
+
class JSONTokener {
|
42
|
+
|
43
|
+
private long character;
|
44
|
+
private boolean eof;
|
45
|
+
private long index;
|
46
|
+
private long line;
|
47
|
+
private char previous;
|
48
|
+
private Reader reader;
|
49
|
+
private boolean usePrevious;
|
50
|
+
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Construct a JSONTokener from a Reader.
|
54
|
+
*
|
55
|
+
* @param reader A reader.
|
56
|
+
*/
|
57
|
+
public JSONTokener(Reader reader) {
|
58
|
+
this.reader = reader.markSupported()
|
59
|
+
? reader
|
60
|
+
: new BufferedReader(reader);
|
61
|
+
this.eof = false;
|
62
|
+
this.usePrevious = false;
|
63
|
+
this.previous = 0;
|
64
|
+
this.index = 0;
|
65
|
+
this.character = 1;
|
66
|
+
this.line = 1;
|
67
|
+
}
|
68
|
+
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Construct a JSONTokener from an InputStream.
|
72
|
+
*/
|
73
|
+
public JSONTokener(InputStream inputStream) {
|
74
|
+
this(new InputStreamReader(inputStream));
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Construct a JSONTokener from a string.
|
80
|
+
*
|
81
|
+
* @param s A source string.
|
82
|
+
*/
|
83
|
+
public JSONTokener(String s) {
|
84
|
+
this(new StringReader(s));
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
/**
|
89
|
+
* Back up one character. This provides a sort of lookahead capability,
|
90
|
+
* so that you can test for a digit or letter before attempting to parse
|
91
|
+
* the next number or identifier.
|
92
|
+
*/
|
93
|
+
public void back() {
|
94
|
+
if (this.usePrevious || this.index <= 0) {
|
95
|
+
throw new RuntimeException("Stepping back two steps is not supported");
|
96
|
+
}
|
97
|
+
this.index -= 1;
|
98
|
+
this.character -= 1;
|
99
|
+
this.usePrevious = true;
|
100
|
+
this.eof = false;
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Get the hex value of a character (base16).
|
106
|
+
* @param c A character between '0' and '9' or between 'A' and 'F' or
|
107
|
+
* between 'a' and 'f'.
|
108
|
+
* @return An int between 0 and 15, or -1 if c was not a hex digit.
|
109
|
+
*/
|
110
|
+
public static int dehexchar(char c) {
|
111
|
+
if (c >= '0' && c <= '9') {
|
112
|
+
return c - '0';
|
113
|
+
}
|
114
|
+
if (c >= 'A' && c <= 'F') {
|
115
|
+
return c - ('A' - 10);
|
116
|
+
}
|
117
|
+
if (c >= 'a' && c <= 'f') {
|
118
|
+
return c - ('a' - 10);
|
119
|
+
}
|
120
|
+
return -1;
|
121
|
+
}
|
122
|
+
|
123
|
+
public boolean end() {
|
124
|
+
return this.eof && !this.usePrevious;
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
/**
|
129
|
+
* Determine if the source string still contains characters that next()
|
130
|
+
* can consume.
|
131
|
+
* @return true if not yet at the end of the source.
|
132
|
+
*/
|
133
|
+
public boolean more() {
|
134
|
+
this.next();
|
135
|
+
if (this.end()) {
|
136
|
+
return false;
|
137
|
+
}
|
138
|
+
this.back();
|
139
|
+
return true;
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
/**
|
144
|
+
* Get the next character in the source string.
|
145
|
+
*
|
146
|
+
* @return The next character, or 0 if past the end of the source string.
|
147
|
+
*/
|
148
|
+
public char next() {
|
149
|
+
int c;
|
150
|
+
if (this.usePrevious) {
|
151
|
+
this.usePrevious = false;
|
152
|
+
c = this.previous;
|
153
|
+
} else {
|
154
|
+
try {
|
155
|
+
c = this.reader.read();
|
156
|
+
} catch (IOException exception) {
|
157
|
+
throw new RuntimeException(exception);
|
158
|
+
}
|
159
|
+
|
160
|
+
if (c <= 0) { // End of stream
|
161
|
+
this.eof = true;
|
162
|
+
c = 0;
|
163
|
+
}
|
164
|
+
}
|
165
|
+
this.index += 1;
|
166
|
+
if (this.previous == '\r') {
|
167
|
+
this.line += 1;
|
168
|
+
this.character = c == '\n' ? 0 : 1;
|
169
|
+
} else if (c == '\n') {
|
170
|
+
this.line += 1;
|
171
|
+
this.character = 0;
|
172
|
+
} else {
|
173
|
+
this.character += 1;
|
174
|
+
}
|
175
|
+
this.previous = (char) c;
|
176
|
+
return this.previous;
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
/**
|
181
|
+
* Consume the next character, and check that it matches a specified
|
182
|
+
* character.
|
183
|
+
* @param c The character to match.
|
184
|
+
* @return The character.
|
185
|
+
* @throws JSONException if the character does not match.
|
186
|
+
*/
|
187
|
+
public char next(char c) {
|
188
|
+
char n = this.next();
|
189
|
+
if (n != c) {
|
190
|
+
throw new RuntimeException("Expected '" + c + "' and instead saw '" + n + "'");
|
191
|
+
}
|
192
|
+
return n;
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
/**
|
197
|
+
* Get the next n characters.
|
198
|
+
*
|
199
|
+
* @param n The number of characters to take.
|
200
|
+
* @return A string of n characters.
|
201
|
+
* @throws JSONException
|
202
|
+
* Substring bounds error if there are not
|
203
|
+
* n characters remaining in the source string.
|
204
|
+
*/
|
205
|
+
public String next(int n) {
|
206
|
+
if (n == 0) {
|
207
|
+
return "";
|
208
|
+
}
|
209
|
+
|
210
|
+
char[] chars = new char[n];
|
211
|
+
int pos = 0;
|
212
|
+
|
213
|
+
while (pos < n) {
|
214
|
+
chars[pos] = this.next();
|
215
|
+
if (this.end()) {
|
216
|
+
throw new RuntimeException("Substring bounds error");
|
217
|
+
}
|
218
|
+
pos += 1;
|
219
|
+
}
|
220
|
+
return new String(chars);
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
/**
|
225
|
+
* Get the next char in the string, skipping whitespace.
|
226
|
+
* @throws JSONException
|
227
|
+
* @return A character, or 0 if there are no more characters.
|
228
|
+
*/
|
229
|
+
public char nextClean() {
|
230
|
+
for (;;) {
|
231
|
+
char c = this.next();
|
232
|
+
if (c == 0 || c > ' ') {
|
233
|
+
return c;
|
234
|
+
}
|
235
|
+
}
|
236
|
+
}
|
237
|
+
|
238
|
+
|
239
|
+
/**
|
240
|
+
* Return the characters up to the next close quote character.
|
241
|
+
* Backslash processing is done. The formal JSON format does not
|
242
|
+
* allow strings in single quotes, but an implementation is allowed to
|
243
|
+
* accept them.
|
244
|
+
* @param quote The quoting character, either
|
245
|
+
* <code>"</code> <small>(double quote)</small> or
|
246
|
+
* <code>'</code> <small>(single quote)</small>.
|
247
|
+
* @return A String.
|
248
|
+
* @throws JSONException Unterminated string.
|
249
|
+
*/
|
250
|
+
public String nextString(char quote) {
|
251
|
+
char c;
|
252
|
+
StringBuilder sb = new StringBuilder();
|
253
|
+
for (;;) {
|
254
|
+
c = this.next();
|
255
|
+
switch (c) {
|
256
|
+
case 0:
|
257
|
+
case '\n':
|
258
|
+
case '\r':
|
259
|
+
throw new RuntimeException("Unterminated string");
|
260
|
+
case '\\':
|
261
|
+
c = this.next();
|
262
|
+
switch (c) {
|
263
|
+
case 'b':
|
264
|
+
sb.append('\b');
|
265
|
+
break;
|
266
|
+
case 't':
|
267
|
+
sb.append('\t');
|
268
|
+
break;
|
269
|
+
case 'n':
|
270
|
+
sb.append('\n');
|
271
|
+
break;
|
272
|
+
case 'f':
|
273
|
+
sb.append('\f');
|
274
|
+
break;
|
275
|
+
case 'r':
|
276
|
+
sb.append('\r');
|
277
|
+
break;
|
278
|
+
case 'u':
|
279
|
+
sb.append((char)Integer.parseInt(this.next(4), 16));
|
280
|
+
break;
|
281
|
+
case '"':
|
282
|
+
case '\'':
|
283
|
+
case '\\':
|
284
|
+
case '/':
|
285
|
+
sb.append(c);
|
286
|
+
break;
|
287
|
+
default:
|
288
|
+
throw new RuntimeException("Illegal escape.");
|
289
|
+
}
|
290
|
+
break;
|
291
|
+
default:
|
292
|
+
if (c == quote) {
|
293
|
+
return sb.toString();
|
294
|
+
}
|
295
|
+
sb.append(c);
|
296
|
+
}
|
297
|
+
}
|
298
|
+
}
|
299
|
+
|
300
|
+
|
301
|
+
/**
|
302
|
+
* Get the text up but not including the specified character or the
|
303
|
+
* end of line, whichever comes first.
|
304
|
+
* @param delimiter A delimiter character.
|
305
|
+
* @return A string.
|
306
|
+
*/
|
307
|
+
public String nextTo(char delimiter) {
|
308
|
+
StringBuilder sb = new StringBuilder();
|
309
|
+
for (;;) {
|
310
|
+
char c = this.next();
|
311
|
+
if (c == delimiter || c == 0 || c == '\n' || c == '\r') {
|
312
|
+
if (c != 0) {
|
313
|
+
this.back();
|
314
|
+
}
|
315
|
+
return sb.toString().trim();
|
316
|
+
}
|
317
|
+
sb.append(c);
|
318
|
+
}
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
/**
|
323
|
+
* Get the text up but not including one of the specified delimiter
|
324
|
+
* characters or the end of line, whichever comes first.
|
325
|
+
* @param delimiters A set of delimiter characters.
|
326
|
+
* @return A string, trimmed.
|
327
|
+
*/
|
328
|
+
public String nextTo(String delimiters) {
|
329
|
+
char c;
|
330
|
+
StringBuilder sb = new StringBuilder();
|
331
|
+
for (;;) {
|
332
|
+
c = this.next();
|
333
|
+
if (delimiters.indexOf(c) >= 0 || c == 0 ||
|
334
|
+
c == '\n' || c == '\r') {
|
335
|
+
if (c != 0) {
|
336
|
+
this.back();
|
337
|
+
}
|
338
|
+
return sb.toString().trim();
|
339
|
+
}
|
340
|
+
sb.append(c);
|
341
|
+
}
|
342
|
+
}
|
343
|
+
|
344
|
+
|
345
|
+
/**
|
346
|
+
* Get the next value. The value can be a Boolean, Double, Integer,
|
347
|
+
* JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object.
|
348
|
+
* @throws JSONException If syntax error.
|
349
|
+
*
|
350
|
+
* @return An object.
|
351
|
+
*/
|
352
|
+
public Object nextValue() {
|
353
|
+
char c = this.nextClean();
|
354
|
+
String string;
|
355
|
+
|
356
|
+
switch (c) {
|
357
|
+
case '"':
|
358
|
+
case '\'':
|
359
|
+
return this.nextString(c);
|
360
|
+
case '{':
|
361
|
+
this.back();
|
362
|
+
return new JSONObject(this);
|
363
|
+
case '[':
|
364
|
+
this.back();
|
365
|
+
return new JSONArray(this);
|
366
|
+
}
|
367
|
+
|
368
|
+
/*
|
369
|
+
* Handle unquoted text. This could be the values true, false, or
|
370
|
+
* null, or it can be a number. An implementation (such as this one)
|
371
|
+
* is allowed to also accept non-standard forms.
|
372
|
+
*
|
373
|
+
* Accumulate characters until we reach the end of the text or a
|
374
|
+
* formatting character.
|
375
|
+
*/
|
376
|
+
|
377
|
+
StringBuilder sb = new StringBuilder();
|
378
|
+
while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
|
379
|
+
sb.append(c);
|
380
|
+
c = this.next();
|
381
|
+
}
|
382
|
+
this.back();
|
383
|
+
|
384
|
+
string = sb.toString().trim();
|
385
|
+
if ("".equals(string)) {
|
386
|
+
throw new RuntimeException("Missing value");
|
387
|
+
}
|
388
|
+
return JSONObject.stringToValue(string);
|
389
|
+
}
|
390
|
+
|
391
|
+
|
392
|
+
/**
|
393
|
+
* Skip characters until the next character is the requested character.
|
394
|
+
* If the requested character is not found, no characters are skipped.
|
395
|
+
* @param to A character to skip to.
|
396
|
+
* @return The requested character, or zero if the requested character
|
397
|
+
* is not found.
|
398
|
+
*/
|
399
|
+
public char skipTo(char to) {
|
400
|
+
char c;
|
401
|
+
try {
|
402
|
+
long startIndex = this.index;
|
403
|
+
long startCharacter = this.character;
|
404
|
+
long startLine = this.line;
|
405
|
+
this.reader.mark(1000000);
|
406
|
+
do {
|
407
|
+
c = this.next();
|
408
|
+
if (c == 0) {
|
409
|
+
this.reader.reset();
|
410
|
+
this.index = startIndex;
|
411
|
+
this.character = startCharacter;
|
412
|
+
this.line = startLine;
|
413
|
+
return c;
|
414
|
+
}
|
415
|
+
} while (c != to);
|
416
|
+
} catch (IOException exc) {
|
417
|
+
throw new RuntimeException(exc);
|
418
|
+
}
|
419
|
+
|
420
|
+
this.back();
|
421
|
+
return c;
|
422
|
+
}
|
423
|
+
|
424
|
+
|
425
|
+
/**
|
426
|
+
* Make a printable string of this JSONTokener.
|
427
|
+
*
|
428
|
+
* @return " at {index} [character {character} line {line}]"
|
429
|
+
*/
|
430
|
+
@Override
|
431
|
+
public String toString() {
|
432
|
+
return " at " + this.index + " [character " + this.character + " line " +
|
433
|
+
this.line + "]";
|
434
|
+
}
|
435
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
package processing.data;
|
2
|
+
|
3
|
+
|
4
|
+
/**
|
5
|
+
* Internal sorter used by several data classes.
|
6
|
+
* Advanced users only, not official API.
|
7
|
+
*/
|
8
|
+
public abstract class Sort implements Runnable {
|
9
|
+
|
10
|
+
public Sort() { }
|
11
|
+
|
12
|
+
|
13
|
+
public void run() {
|
14
|
+
int c = size();
|
15
|
+
if (c > 1) {
|
16
|
+
sort(0, c - 1);
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
|
21
|
+
protected void sort(int i, int j) {
|
22
|
+
int pivotIndex = (i+j)/2;
|
23
|
+
swap(pivotIndex, j);
|
24
|
+
int k = partition(i-1, j);
|
25
|
+
swap(k, j);
|
26
|
+
if ((k-i) > 1) sort(i, k-1);
|
27
|
+
if ((j-k) > 1) sort(k+1, j);
|
28
|
+
}
|
29
|
+
|
30
|
+
|
31
|
+
protected int partition(int left, int right) {
|
32
|
+
int pivot = right;
|
33
|
+
do {
|
34
|
+
while (compare(++left, pivot) < 0) { }
|
35
|
+
while ((right != 0) && (compare(--right, pivot) > 0)) { }
|
36
|
+
swap(left, right);
|
37
|
+
} while (left < right);
|
38
|
+
swap(left, right);
|
39
|
+
return left;
|
40
|
+
}
|
41
|
+
|
42
|
+
|
43
|
+
abstract public int size();
|
44
|
+
abstract public float compare(int a, int b);
|
45
|
+
abstract public void swap(int a, int b);
|
46
|
+
}
|