MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / parse

Method parse

CodenameOne/src/com/codename1/io/JSONParser.java:316–587  ·  view source on GitHub ↗
(Reader i, JSONParseCallback callback)

Source from the content-addressed store, hash-verified

314 ///
315 /// - `IOException`: if thrown by the stream
316 @SuppressWarnings("PMD.SwitchStmtsShouldHaveDefault")
317 public static void parse(Reader i, JSONParseCallback callback) throws IOException {
318 boolean quoteMode = false;
319 ReaderClass rc = new ReaderClass();
320 rc.buffOffset = 0;
321 rc.buffSize = -1;
322 int row = 1;
323 int column = 1;
324 StringBuilder currentToken = new StringBuilder();
325 KeyStack blocks = new KeyStack();
326 String currentBlock = "";
327 String lastKey = null;
328 try {
329 while (callback.isAlive()) {
330 int currentChar = rc.read(i);
331 if (currentChar < 0) {
332 return;
333 }
334 char c = (char) currentChar;
335 if (c == '\n') {
336 row++;
337 column = 0;
338 } else {
339 column++;
340 }
341
342 if (quoteMode) {
343 switch (c) {
344 case '"':
345 String v = currentToken.toString();
346 callback.stringToken(v);
347 if (lastKey != null) {
348 callback.keyValue(lastKey, v);
349 lastKey = null;
350 } else {
351 lastKey = v;
352 }
353 currentToken.setLength(0);
354 quoteMode = false;
355 continue;
356 case '\\':
357 c = (char) rc.read(i);
358 if (c == 'u') {
359 String unicode = "" + ((char) rc.read(i)) + ((char) rc.read(i)) + ((char) rc.read(i)) + ((char) rc.read(i));
360 try {
361 c = (char) Integer.parseInt(unicode, 16);
362 } catch (NumberFormatException err) {
363 // problem in parsing the u notation!
364 Log.e(err);
365 Log.p("Error in parsing \\u" + unicode);
366 }
367 } else {
368 switch (c) {
369 case 'n':
370 currentToken.append('\n');
371 continue;
372 case 't':
373 currentToken.append('\t');

Callers 4

parseJSONMethod · 0.95
readResponseMethod · 0.95
readResponseMethod · 0.95
readResponseMethod · 0.95

Calls 15

readMethod · 0.95
toStringMethod · 0.95
setLengthMethod · 0.95
parseIntMethod · 0.95
eMethod · 0.95
pMethod · 0.95
appendMethod · 0.95
useBooleanMethod · 0.95
lengthMethod · 0.95
peekMethod · 0.95
pushMethod · 0.95
useLongsMethod · 0.95

Tested by

no test coverage detected