Changeset 13231 in josm for trunk/src/org/glassfish/json/JsonTokenizer.java
- Timestamp:
- 2017-12-23T02:40:43+01:00 (8 years ago)
- File:
-
- 1 edited
-
trunk/src/org/glassfish/json/JsonTokenizer.java (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/glassfish/json/JsonTokenizer.java
r6756 r13231 2 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 3 * 4 * Copyright (c) 2012-201 3Oracle and/or its affiliates. All rights reserved.4 * Copyright (c) 2012-2017 Oracle and/or its affiliates. All rights reserved. 5 5 * 6 6 * The contents of this file are subject to the terms of either the GNU … … 9 9 * may not use this file except in compliance with the License. You can 10 10 * obtain a copy of the License at 11 * https:// glassfish.dev.java.net/public/CDDL+GPL_1_1.html12 * or packager/legal/LICENSE.txt. See the License for the specific11 * https://oss.oracle.com/licenses/CDDL+GPL-1.1 12 * or LICENSE.txt. See the License for the specific 13 13 * language governing permissions and limitations under the License. 14 14 * 15 15 * When distributing the software, include this License Header Notice in each 16 * file and include the License file at packager/legal/LICENSE.txt.16 * file and include the License file at LICENSE.txt. 17 17 * 18 18 * GPL Classpath Exception: … … 293 293 } 294 294 } 295 readBegin--; 296 storeEnd = readBegin; 295 if (ch != -1) { 296 // Only reset readBegin if eof has not been reached 297 readBegin--; 298 storeEnd = readBegin; 299 } 297 300 } 298 301 … … 417 420 } 418 421 422 boolean hasNextToken() { 423 reset(); 424 int ch = peek(); 425 426 // whitespace 427 while (ch == 0x20 || ch == 0x09 || ch == 0x0a || ch == 0x0d) { 428 if (ch == '\r') { 429 ++lineNo; 430 ++readBegin; 431 ch = peek(); 432 if (ch == '\n') { 433 lastLineOffset = bufferOffset+readBegin+1; 434 } else { 435 lastLineOffset = bufferOffset+readBegin; 436 continue; 437 } 438 } else if (ch == '\n') { 439 ++lineNo; 440 lastLineOffset = bufferOffset+readBegin+1; 441 } 442 ++readBegin; 443 ch = peek(); 444 } 445 return ch != -1; 446 } 447 448 private int peek() { 449 try { 450 if (readBegin == readEnd) { // need to fill the buffer 451 int len = fillBuf(); 452 if (len == -1) { 453 return -1; 454 } 455 assert len != 0; 456 readBegin = storeEnd; 457 readEnd = readBegin+len; 458 } 459 return buf[readBegin]; 460 } catch (IOException ioe) { 461 throw new JsonException(JsonMessages.TOKENIZER_IO_ERR(), ioe); 462 } 463 } 464 419 465 // Gives the location of the last char. Used for 420 466 // JsonParsingException.getLocation … … 499 545 // no need to create BigDecimal for common integer values (1-9 digits) 500 546 int storeLen = storeEnd-storeBegin; 501 if (!fracOrExp && (storeLen <= 9 || (minus && storeLen == 10))) {547 if (!fracOrExp && (storeLen <= 9 || (minus && storeLen <= 10))) { 502 548 int num = 0; 503 549 int i = minus ? 1 : 0; … … 510 556 } 511 557 } 558 559 long getLong() { 560 // no need to create BigDecimal for common integer values (1-18 digits) 561 int storeLen = storeEnd-storeBegin; 562 if (!fracOrExp && (storeLen <= 18 || (minus && storeLen <= 19))) { 563 long num = 0; 564 int i = minus ? 1 : 0; 565 for(; i < storeLen; i++) { 566 num = num * 10 + (buf[storeBegin+i] - '0'); 567 } 568 return minus ? -num : num; 569 } else { 570 return getBigDecimal().longValue(); 571 } 572 } 512 573 513 574 // returns true for common integer values (1-9 digits). … … 515 576 boolean isDefinitelyInt() { 516 577 int storeLen = storeEnd-storeBegin; 517 return !fracOrExp && (storeLen <= 9 || (minus && storeLen == 10)); 578 return !fracOrExp && (storeLen <= 9 || (minus && storeLen <= 10)); 579 } 580 581 // returns true for common long values (1-18 digits). 582 // So there are cases it will return false even though the number is long 583 boolean isDefinitelyLong() { 584 int storeLen = storeEnd-storeBegin; 585 return !fracOrExp && (storeLen <= 18 || (minus && storeLen <= 19)); 518 586 } 519 587
Note:
See TracChangeset
for help on using the changeset viewer.
