Package org.apache.groovy.json.internal
Class CharScanner
java.lang.Object
org.apache.groovy.json.internal.CharScanner
Low-level character scanning utilities used while parsing JSON values.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intCharacter code for'0'.protected static final intCharacter code for'9'.protected static final intClosing bracket character code.protected static final intClosing curly brace character code.protected static final intComma character code.protected static final intDecimal point character code.protected static final intUppercase exponent marker.protected static final intLowercase exponent marker.protected static final intMinus sign character code.protected static final intPlus sign character code. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringdebugCharDescription(int c) Returns a debug string for a character code.static StringerrorDetails(String message, char[] array, int index, int ch) Builds a human-readable parse error description for the current character position.static booleanhasDecimalChar(char[] chars, boolean negative) Tests whether a character range contains decimal punctuation.static booleanisDecimalChar(int currentChar) Tests whether the supplied code point is decimal punctuation.static booleanisDecimalDigit(int c) Tests whether the supplied code point can appear in a decimal number.protected static booleanisDelimiter(int c) Tests whether the supplied code point terminates a JSON number token.static booleanisDigit(int c) Tests whether the supplied code point is an ASCII digit.static booleanisInteger(char[] digitChars) Tests whether the supplied digits fit in anint.static booleanisInteger(char[] digitChars, int offset, int len) Tests whether the supplied digit range fits in anint.static booleanisLong(char[] digitChars) Tests whether the supplied digits fit in along.static booleanisLong(char[] digitChars, int offset, int len) Tests whether the supplied digit range fits in along.static booleanisNumberDigit(int c) Tests whether the supplied code point is a numeric digit.static BigDecimalparseBigDecimal(char[] buffer) Parses aBigDecimalfrom the supplied characters.static doubleparseDouble(char[] buffer, int from, int to) Parses adoublefrom a character range.static floatparseFloat(char[] buffer, int from, int to) Parses afloatfrom a character range.static intparseInt(char[] digitChars) Parses anintfrom the supplied digit characters.static intparseIntFromTo(char[] digitChars, int offset, int to) Parses anintfrom a character range.static intparseIntFromToIgnoreDot(char[] digitChars, int offset, int to) Parses anintfrom a character range while ignoring decimal points.static NumberparseJsonNumber(char[] buffer) Parses a JSON number from the supplied character array.static NumberparseJsonNumber(char[] buffer, int from, int to) Parses a JSON number from a character range.static NumberparseJsonNumber(char[] buffer, int from, int max, int[] size) Parses a JSON number and optionally reports the stopping index.static longparseLong(char[] digitChars) Parses alongfrom the supplied digit characters.static longparseLongFromTo(char[] digitChars, int offset, int to) Parses alongfrom a character range.static longparseLongFromToIgnoreDot(char[] digitChars, int offset, int to) Parses alongfrom a character range while ignoring decimal points.static char[]readNumber(char[] array, int idx, int len) Copies a contiguous JSON number token into a new array.static intskipWhiteSpace(char[] array, int index, int length) Advances past ASCII whitespace.
-
Field Details
-
COMMA
protected static final int COMMAComma character code.- See Also:
-
CLOSED_CURLY
protected static final int CLOSED_CURLYClosing curly brace character code.- See Also:
-
CLOSED_BRACKET
protected static final int CLOSED_BRACKETClosing bracket character code.- See Also:
-
LETTER_E
protected static final int LETTER_ELowercase exponent marker.- See Also:
-
LETTER_BIG_E
protected static final int LETTER_BIG_EUppercase exponent marker.- See Also:
-
DECIMAL_POINT
protected static final int DECIMAL_POINTDecimal point character code.- See Also:
-
ALPHA_0
protected static final int ALPHA_0Character code for'0'.- See Also:
-
ALPHA_9
protected static final int ALPHA_9Character code for'9'.- See Also:
-
MINUS
protected static final int MINUSMinus sign character code.- See Also:
-
PLUS
protected static final int PLUSPlus sign character code.- See Also:
-
-
Constructor Details
-
CharScanner
public CharScanner()
-
-
Method Details
-
isDigit
public static boolean isDigit(int c) Tests whether the supplied code point is an ASCII digit.- Parameters:
c- the character code to test- Returns:
trueif the code point is between'0'and'9'
-
isDecimalDigit
public static boolean isDecimalDigit(int c) Tests whether the supplied code point can appear in a decimal number.- Parameters:
c- the character code to test- Returns:
truefor digits and decimal punctuation
-
isDecimalChar
public static boolean isDecimalChar(int currentChar) Tests whether the supplied code point is decimal punctuation.- Parameters:
currentChar- the character code to test- Returns:
truefor sign, exponent, or decimal point characters
-
hasDecimalChar
public static boolean hasDecimalChar(char[] chars, boolean negative) Tests whether a character range contains decimal punctuation.- Parameters:
chars- the character array to inspectnegative- whether the first character is a sign and should be skipped- Returns:
trueif a decimal marker or exponent marker is present
-
isLong
public static boolean isLong(char[] digitChars) Tests whether the supplied digits fit in along.- Parameters:
digitChars- the digit characters to test- Returns:
trueif the value is within thelongrange
-
isLong
public static boolean isLong(char[] digitChars, int offset, int len) Tests whether the supplied digit range fits in along.- Parameters:
digitChars- the digit characters to testoffset- the inclusive range startlen- the number of characters to compare- Returns:
trueif the value is within thelongrange
-
isInteger
public static boolean isInteger(char[] digitChars) Tests whether the supplied digits fit in anint.- Parameters:
digitChars- the digit characters to test- Returns:
trueif the value is within theintrange
-
isInteger
public static boolean isInteger(char[] digitChars, int offset, int len) Tests whether the supplied digit range fits in anint.- Parameters:
digitChars- the digit characters to testoffset- the inclusive range startlen- the number of characters to compare- Returns:
trueif the value is within theintrange
-
parseInt
public static int parseInt(char[] digitChars) Parses anintfrom the supplied digit characters.- Parameters:
digitChars- the digit characters to parse- Returns:
- the parsed value
-
parseIntFromTo
public static int parseIntFromTo(char[] digitChars, int offset, int to) Parses anintfrom a character range.- Parameters:
digitChars- the digit characters to parseoffset- the inclusive range startto- the exclusive range end- Returns:
- the parsed value
-
parseIntFromToIgnoreDot
public static int parseIntFromToIgnoreDot(char[] digitChars, int offset, int to) Parses anintfrom a character range while ignoring decimal points.- Parameters:
digitChars- the digit characters to parseoffset- the inclusive range startto- the exclusive range end- Returns:
- the parsed value
-
parseLongFromToIgnoreDot
public static long parseLongFromToIgnoreDot(char[] digitChars, int offset, int to) Parses alongfrom a character range while ignoring decimal points.- Parameters:
digitChars- the digit characters to parseoffset- the inclusive range startto- the exclusive range end- Returns:
- the parsed value
-
parseLongFromTo
public static long parseLongFromTo(char[] digitChars, int offset, int to) Parses alongfrom a character range.- Parameters:
digitChars- the digit characters to parseoffset- the inclusive range startto- the exclusive range end- Returns:
- the parsed value
-
parseLong
public static long parseLong(char[] digitChars) Parses alongfrom the supplied digit characters.- Parameters:
digitChars- the digit characters to parse- Returns:
- the parsed value
-
parseJsonNumber
Parses a JSON number from the supplied character array.- Parameters:
buffer- the character array containing the number- Returns:
- the parsed
Number
-
parseJsonNumber
Parses a JSON number from a character range.- Parameters:
buffer- the character array containing the numberfrom- the inclusive range startto- the exclusive range end- Returns:
- the parsed
Number
-
isNumberDigit
public static boolean isNumberDigit(int c) Tests whether the supplied code point is a numeric digit.- Parameters:
c- the character code to test- Returns:
trueif the code point is between'0'and'9'
-
isDelimiter
protected static boolean isDelimiter(int c) Tests whether the supplied code point terminates a JSON number token.- Parameters:
c- the character code to test- Returns:
trueif the code point is a structural delimiter
-
parseJsonNumber
Parses a JSON number and optionally reports the stopping index.- Parameters:
buffer- the character array containing the numberfrom- the inclusive range startmax- the exclusive scan limitsize- optional single-element output array receiving the stopping index- Returns:
- the parsed
Number
-
parseBigDecimal
Parses aBigDecimalfrom the supplied characters.- Parameters:
buffer- the character array to parse- Returns:
- the parsed decimal value
-
parseFloat
public static float parseFloat(char[] buffer, int from, int to) Parses afloatfrom a character range.- Parameters:
buffer- the character array to parsefrom- the inclusive range startto- the exclusive range end- Returns:
- the parsed value
-
parseDouble
public static double parseDouble(char[] buffer, int from, int to) Parses adoublefrom a character range.- Parameters:
buffer- the character array to parsefrom- the inclusive range startto- the exclusive range end- Returns:
- the parsed value
-
skipWhiteSpace
public static int skipWhiteSpace(char[] array, int index, int length) Advances past ASCII whitespace.- Parameters:
array- the character array to scanindex- the index to start fromlength- the exclusive scan limit- Returns:
- the first index whose character is greater than space, or
length
-
readNumber
public static char[] readNumber(char[] array, int idx, int len) Copies a contiguous JSON number token into a new array.- Parameters:
array- the source character arrayidx- the index at which the number startslen- the exclusive scan limit- Returns:
- a new array containing the number token
-
errorDetails
Builds a human-readable parse error description for the current character position.- Parameters:
message- the high-level error messagearray- the source character arrayindex- the failing indexch- the current character code- Returns:
- the formatted diagnostic text
-
debugCharDescription
Returns a debug string for a character code.- Parameters:
c- the character code to describe- Returns:
- a printable character description
-