|
Lines 1364-1473
Link Here
|
| 1364 |
} |
1364 |
} |
| 1365 |
throw new InvalidInputException(INVALID_CHARACTER_CONSTANT); |
1365 |
throw new InvalidInputException(INVALID_CHARACTER_CONSTANT); |
| 1366 |
case '"' : |
1366 |
case '"' : |
| 1367 |
try { |
1367 |
return scanStringLiteral(); |
| 1368 |
// consume next character |
|
|
| 1369 |
this.unicodeAsBackSlash = false; |
| 1370 |
boolean isUnicode = false; |
| 1371 |
if (((this.currentCharacter = this.source[this.currentPosition++]) == '\\') |
| 1372 |
&& (this.source[this.currentPosition] == 'u')) { |
| 1373 |
getNextUnicodeChar(); |
| 1374 |
isUnicode = true; |
| 1375 |
} else { |
| 1376 |
if (this.withoutUnicodePtr != 0) { |
| 1377 |
unicodeStore(); |
| 1378 |
} |
| 1379 |
} |
| 1380 |
|
| 1381 |
while (this.currentCharacter != '"') { |
| 1382 |
/**** \r and \n are not valid in string literals ****/ |
| 1383 |
if ((this.currentCharacter == '\n') || (this.currentCharacter == '\r')) { |
| 1384 |
// relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed |
| 1385 |
if (isUnicode) { |
| 1386 |
int start = this.currentPosition; |
| 1387 |
for (int lookAhead = 0; lookAhead < 50; lookAhead++) { |
| 1388 |
if (this.currentPosition >= this.eofPosition) { |
| 1389 |
this.currentPosition = start; |
| 1390 |
break; |
| 1391 |
} |
| 1392 |
if (((this.currentCharacter = this.source[this.currentPosition++]) == '\\') && (this.source[this.currentPosition] == 'u')) { |
| 1393 |
isUnicode = true; |
| 1394 |
getNextUnicodeChar(); |
| 1395 |
} else { |
| 1396 |
isUnicode = false; |
| 1397 |
} |
| 1398 |
if (!isUnicode && this.currentCharacter == '\n') { |
| 1399 |
this.currentPosition--; // set current position on new line character |
| 1400 |
break; |
| 1401 |
} |
| 1402 |
if (this.currentCharacter == '\"') { |
| 1403 |
throw new InvalidInputException(INVALID_CHAR_IN_STRING); |
| 1404 |
} |
| 1405 |
} |
| 1406 |
} else { |
| 1407 |
this.currentPosition--; // set current position on new line character |
| 1408 |
} |
| 1409 |
throw new InvalidInputException(INVALID_CHAR_IN_STRING); |
| 1410 |
} |
| 1411 |
if (this.currentCharacter == '\\') { |
| 1412 |
if (this.unicodeAsBackSlash) { |
| 1413 |
this.withoutUnicodePtr--; |
| 1414 |
// consume next character |
| 1415 |
this.unicodeAsBackSlash = false; |
| 1416 |
if (((this.currentCharacter = this.source[this.currentPosition++]) == '\\') && (this.source[this.currentPosition] == 'u')) { |
| 1417 |
getNextUnicodeChar(); |
| 1418 |
isUnicode = true; |
| 1419 |
this.withoutUnicodePtr--; |
| 1420 |
} else { |
| 1421 |
isUnicode = false; |
| 1422 |
} |
| 1423 |
} else { |
| 1424 |
if (this.withoutUnicodePtr == 0) { |
| 1425 |
unicodeInitializeBuffer(this.currentPosition - this.startPosition); |
| 1426 |
} |
| 1427 |
this.withoutUnicodePtr --; |
| 1428 |
this.currentCharacter = this.source[this.currentPosition++]; |
| 1429 |
} |
| 1430 |
// we need to compute the escape character in a separate buffer |
| 1431 |
scanEscapeCharacter(); |
| 1432 |
if (this.withoutUnicodePtr != 0) { |
| 1433 |
unicodeStore(); |
| 1434 |
} |
| 1435 |
} |
| 1436 |
// consume next character |
| 1437 |
this.unicodeAsBackSlash = false; |
| 1438 |
if (((this.currentCharacter = this.source[this.currentPosition++]) == '\\') |
| 1439 |
&& (this.source[this.currentPosition] == 'u')) { |
| 1440 |
getNextUnicodeChar(); |
| 1441 |
isUnicode = true; |
| 1442 |
} else { |
| 1443 |
isUnicode = false; |
| 1444 |
if (this.withoutUnicodePtr != 0) { |
| 1445 |
unicodeStore(); |
| 1446 |
} |
| 1447 |
} |
| 1448 |
|
| 1449 |
} |
| 1450 |
} catch (IndexOutOfBoundsException e) { |
| 1451 |
this.currentPosition--; |
| 1452 |
throw new InvalidInputException(UNTERMINATED_STRING); |
| 1453 |
} catch (InvalidInputException e) { |
| 1454 |
if (e.getMessage().equals(INVALID_ESCAPE)) { |
| 1455 |
// relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed |
| 1456 |
for (int lookAhead = 0; lookAhead < 50; lookAhead++) { |
| 1457 |
if (this.currentPosition + lookAhead == this.eofPosition) |
| 1458 |
break; |
| 1459 |
if (this.source[this.currentPosition + lookAhead] == '\n') |
| 1460 |
break; |
| 1461 |
if (this.source[this.currentPosition + lookAhead] == '\"') { |
| 1462 |
this.currentPosition += lookAhead + 1; |
| 1463 |
break; |
| 1464 |
} |
| 1465 |
} |
| 1466 |
|
| 1467 |
} |
| 1468 |
throw e; // rethrow |
| 1469 |
} |
| 1470 |
return TokenNameStringLiteral; |
| 1471 |
case '/' : |
1368 |
case '/' : |
| 1472 |
if (!this.skipComments) { |
1369 |
if (!this.skipComments) { |
| 1473 |
int test = getNextChar('/', '*'); |
1370 |
int test = getNextChar('/', '*'); |
|
Lines 1717-1722
Link Here
|
| 1717 |
} |
1614 |
} |
| 1718 |
return TokenNameEOF; |
1615 |
return TokenNameEOF; |
| 1719 |
} |
1616 |
} |
|
|
1617 |
|
| 1618 |
protected int scanStringLiteral() throws InvalidInputException { |
| 1619 |
try { |
| 1620 |
// consume next character |
| 1621 |
this.unicodeAsBackSlash = false; |
| 1622 |
boolean isUnicode = false; |
| 1623 |
if (((this.currentCharacter = this.source[this.currentPosition++]) == '\\') |
| 1624 |
&& (this.source[this.currentPosition] == 'u')) { |
| 1625 |
getNextUnicodeChar(); |
| 1626 |
isUnicode = true; |
| 1627 |
} else { |
| 1628 |
if (this.withoutUnicodePtr != 0) { |
| 1629 |
unicodeStore(); |
| 1630 |
} |
| 1631 |
} |
| 1632 |
|
| 1633 |
while (this.currentCharacter != '"') { |
| 1634 |
/**** \r and \n are not valid in string literals ****/ |
| 1635 |
if ((this.currentCharacter == '\n') || (this.currentCharacter == '\r')) { |
| 1636 |
// relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed |
| 1637 |
if (isUnicode) { |
| 1638 |
int start = this.currentPosition; |
| 1639 |
for (int lookAhead = 0; lookAhead < 50; lookAhead++) { |
| 1640 |
if (this.currentPosition >= this.eofPosition) { |
| 1641 |
this.currentPosition = start; |
| 1642 |
break; |
| 1643 |
} |
| 1644 |
if (((this.currentCharacter = this.source[this.currentPosition++]) == '\\') && (this.source[this.currentPosition] == 'u')) { |
| 1645 |
isUnicode = true; |
| 1646 |
getNextUnicodeChar(); |
| 1647 |
} else { |
| 1648 |
isUnicode = false; |
| 1649 |
} |
| 1650 |
if (!isUnicode && this.currentCharacter == '\n') { |
| 1651 |
this.currentPosition--; // set current position on new line character |
| 1652 |
break; |
| 1653 |
} |
| 1654 |
if (this.currentCharacter == '\"') { |
| 1655 |
throw new InvalidInputException(INVALID_CHAR_IN_STRING); |
| 1656 |
} |
| 1657 |
} |
| 1658 |
} else { |
| 1659 |
this.currentPosition--; // set current position on new line character |
| 1660 |
} |
| 1661 |
throw new InvalidInputException(INVALID_CHAR_IN_STRING); |
| 1662 |
} |
| 1663 |
if (this.currentCharacter == '\\') { |
| 1664 |
if (this.unicodeAsBackSlash) { |
| 1665 |
this.withoutUnicodePtr--; |
| 1666 |
// consume next character |
| 1667 |
this.unicodeAsBackSlash = false; |
| 1668 |
if (((this.currentCharacter = this.source[this.currentPosition++]) == '\\') && (this.source[this.currentPosition] == 'u')) { |
| 1669 |
getNextUnicodeChar(); |
| 1670 |
isUnicode = true; |
| 1671 |
this.withoutUnicodePtr--; |
| 1672 |
} else { |
| 1673 |
isUnicode = false; |
| 1674 |
} |
| 1675 |
} else { |
| 1676 |
if (this.withoutUnicodePtr == 0) { |
| 1677 |
unicodeInitializeBuffer(this.currentPosition - this.startPosition); |
| 1678 |
} |
| 1679 |
this.withoutUnicodePtr --; |
| 1680 |
this.currentCharacter = this.source[this.currentPosition++]; |
| 1681 |
} |
| 1682 |
// we need to compute the escape character in a separate buffer |
| 1683 |
scanEscapeCharacter(); |
| 1684 |
if (this.withoutUnicodePtr != 0) { |
| 1685 |
unicodeStore(); |
| 1686 |
} |
| 1687 |
} |
| 1688 |
// consume next character |
| 1689 |
this.unicodeAsBackSlash = false; |
| 1690 |
if (((this.currentCharacter = this.source[this.currentPosition++]) == '\\') |
| 1691 |
&& (this.source[this.currentPosition] == 'u')) { |
| 1692 |
getNextUnicodeChar(); |
| 1693 |
isUnicode = true; |
| 1694 |
} else { |
| 1695 |
isUnicode = false; |
| 1696 |
if (this.withoutUnicodePtr != 0) { |
| 1697 |
unicodeStore(); |
| 1698 |
} |
| 1699 |
} |
| 1700 |
|
| 1701 |
} |
| 1702 |
} catch (IndexOutOfBoundsException e) { |
| 1703 |
this.currentPosition--; |
| 1704 |
throw new InvalidInputException(UNTERMINATED_STRING); |
| 1705 |
} catch (InvalidInputException e) { |
| 1706 |
if (e.getMessage().equals(INVALID_ESCAPE)) { |
| 1707 |
// relocate if finding another quote fairly close: thus unicode '/u000D' will be fully consumed |
| 1708 |
for (int lookAhead = 0; lookAhead < 50; lookAhead++) { |
| 1709 |
if (this.currentPosition + lookAhead == this.eofPosition) |
| 1710 |
break; |
| 1711 |
if (this.source[this.currentPosition + lookAhead] == '\n') |
| 1712 |
break; |
| 1713 |
if (this.source[this.currentPosition + lookAhead] == '\"') { |
| 1714 |
this.currentPosition += lookAhead + 1; |
| 1715 |
break; |
| 1716 |
} |
| 1717 |
} |
| 1718 |
|
| 1719 |
} |
| 1720 |
throw e; // rethrow |
| 1721 |
} |
| 1722 |
return TokenNameStringLiteral; |
| 1723 |
} |
| 1720 |
public void getNextUnicodeChar() |
1724 |
public void getNextUnicodeChar() |
| 1721 |
throws InvalidInputException { |
1725 |
throws InvalidInputException { |
| 1722 |
//VOID |
1726 |
//VOID |