Package org.apache.groovy.json.internal

# Class CharScanner

java.lang.Object
org.apache.groovy.json.internal.CharScanner

public class CharScanner extends Object
Low-level character scanning utilities used while parsing JSON values.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static final int`
  `ALPHA_0`
  Character code for `'0'`.
  `protected static final int`
  `ALPHA_9`
  Character code for `'9'`.
  `protected static final int`
  `CLOSED_BRACKET`
  Closing bracket character code.
  `protected static final int`
  `CLOSED_CURLY`
  Closing curly brace character code.
  `protected static final int`
  `COMMA`
  Comma character code.
  `protected static final int`
  `DECIMAL_POINT`
  Decimal point character code.
  `protected static final int`
  `LETTER_BIG_E`
  Uppercase exponent marker.
  `protected static final int`
  `LETTER_E`
  Lowercase exponent marker.
  `protected static final int`
  `MINUS`
  Minus sign character code.
  `protected static final int`
  `PLUS`
  Plus sign character code.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `CharScanner()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static String`
  `debugCharDescription(int c)`
  Returns a debug string for a character code.
  `static String`
  `errorDetails(String message, char[] array, int index, int ch)`
  Builds a human-readable parse error description for the current character position.
  `static boolean`
  `hasDecimalChar(char[] chars, boolean negative)`
  Tests whether a character range contains decimal punctuation.
  `static boolean`
  `isDecimalChar(int currentChar)`
  Tests whether the supplied code point is decimal punctuation.
  `static boolean`
  `isDecimalDigit(int c)`
  Tests whether the supplied code point can appear in a decimal number.
  `protected static boolean`
  `isDelimiter(int c)`
  Tests whether the supplied code point terminates a JSON number token.
  `static boolean`
  `isDigit(int c)`
  Tests whether the supplied code point is an ASCII digit.
  `static boolean`
  `isInteger(char[] digitChars)`
  Tests whether the supplied digits fit in an `int`.
  `static boolean`
  `isInteger(char[] digitChars, int offset, int len)`
  Tests whether the supplied digit range fits in an `int`.
  `static boolean`
  `isLong(char[] digitChars)`
  Tests whether the supplied digits fit in a `long`.
  `static boolean`
  `isLong(char[] digitChars, int offset, int len)`
  Tests whether the supplied digit range fits in a `long`.
  `static boolean`
  `isNumberDigit(int c)`
  Tests whether the supplied code point is a numeric digit.
  `static BigDecimal`
  `parseBigDecimal(char[] buffer)`
  Parses a `BigDecimal` from the supplied characters.
  `static double`
  `parseDouble(char[] buffer, int from, int to)`
  Parses a `double` from a character range.
  `static float`
  `parseFloat(char[] buffer, int from, int to)`
  Parses a `float` from a character range.
  `static int`
  `parseInt(char[] digitChars)`
  Parses an `int` from the supplied digit characters.
  `static int`
  `parseIntFromTo(char[] digitChars, int offset, int to)`
  Parses an `int` from a character range.
  `static int`
  `parseIntFromToIgnoreDot(char[] digitChars, int offset, int to)`
  Parses an `int` from a character range while ignoring decimal points.
  `static Number`
  `parseJsonNumber(char[] buffer)`
  Parses a JSON number from the supplied character array.
  `static Number`
  `parseJsonNumber(char[] buffer, int from, int to)`
  Parses a JSON number from a character range.
  `static Number`
  `parseJsonNumber(char[] buffer, int from, int max, int[] size)`
  Parses a JSON number and optionally reports the stopping index.
  `static Number`
  `parseJsonNumber(char[] buffer, int from, int max, int[] size, int maxNumberLength)`
  Parses a JSON number and optionally reports the stopping index, bounding the length of the number token.
  `static long`
  `parseLong(char[] digitChars)`
  Parses a `long` from the supplied digit characters.
  `static long`
  `parseLongFromTo(char[] digitChars, int offset, int to)`
  Parses a `long` from a character range.
  `static long`
  `parseLongFromToIgnoreDot(char[] digitChars, int offset, int to)`
  Parses a `long` from 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 int`
  `skipWhiteSpace(char[] array, int index, int length)`
  Advances past ASCII whitespace.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### COMMA

    protected static final int COMMA
    Comma character code.
    See Also:
      - Constant Field Values

  - ### CLOSED_CURLY

    protected static final int CLOSED_CURLY
    Closing curly brace character code.
    See Also:
      - Constant Field Values

  - ### CLOSED_BRACKET

    protected static final int CLOSED_BRACKET
    Closing bracket character code.
    See Also:
      - Constant Field Values

  - ### LETTER_E

    protected static final int LETTER_E
    Lowercase exponent marker.
    See Also:
      - Constant Field Values

  - ### LETTER_BIG_E

    protected static final int LETTER_BIG_E
    Uppercase exponent marker.
    See Also:
      - Constant Field Values

  - ### DECIMAL_POINT

    protected static final int DECIMAL_POINT
    Decimal point character code.
    See Also:
      - Constant Field Values

  - ### ALPHA_0

    protected static final int ALPHA_0
    Character code for `'0'`.
    See Also:
      - Constant Field Values

  - ### ALPHA_9

    protected static final int ALPHA_9
    Character code for `'9'`.
    See Also:
      - Constant Field Values

  - ### MINUS

    protected static final int MINUS
    Minus sign character code.
    See Also:
      - Constant Field Values

  - ### PLUS

    protected static final int PLUS
    Plus sign character code.
    See Also:
      - Constant Field Values

- ## 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:
      `true` if 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:
      `true` for 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:
      `true` for 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 inspect
      `negative` - whether the first character is a sign and should be skipped
    Returns:
      `true` if a decimal marker or exponent marker is present

  - ### isLong

    public static boolean isLong(char[] digitChars)
    Tests whether the supplied digits fit in a `long`.
    Parameters:
      `digitChars` - the digit characters to test
    Returns:
      `true` if the value is within the `long` range

  - ### isLong

    public static boolean isLong(char[] digitChars, int offset, int len)
    Tests whether the supplied digit range fits in a `long`.
    Parameters:
      `digitChars` - the digit characters to test
      `offset` - the inclusive range start
      `len` - the number of characters to compare
    Returns:
      `true` if the value is within the `long` range

  - ### isInteger

    public static boolean isInteger(char[] digitChars)
    Tests whether the supplied digits fit in an `int`.
    Parameters:
      `digitChars` - the digit characters to test
    Returns:
      `true` if the value is within the `int` range

  - ### isInteger

    public static boolean isInteger(char[] digitChars, int offset, int len)
    Tests whether the supplied digit range fits in an `int`.
    Parameters:
      `digitChars` - the digit characters to test
      `offset` - the inclusive range start
      `len` - the number of characters to compare
    Returns:
      `true` if the value is within the `int` range

  - ### parseInt

    public static int parseInt(char[] digitChars)
    Parses an `int` from 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 an `int` from a character range.
    Parameters:
      `digitChars` - the digit characters to parse
      `offset` - the inclusive range start
      `to` - the exclusive range end
    Returns:
      the parsed value

  - ### parseIntFromToIgnoreDot

    public static int parseIntFromToIgnoreDot(char[] digitChars, int offset, int to)
    Parses an `int` from a character range while ignoring decimal points.
    Parameters:
      `digitChars` - the digit characters to parse
      `offset` - the inclusive range start
      `to` - the exclusive range end
    Returns:
      the parsed value

  - ### parseLongFromToIgnoreDot

    public static long parseLongFromToIgnoreDot(char[] digitChars, int offset, int to)
    Parses a `long` from a character range while ignoring decimal points.
    Parameters:
      `digitChars` - the digit characters to parse
      `offset` - the inclusive range start
      `to` - the exclusive range end
    Returns:
      the parsed value

  - ### parseLongFromTo

    public static long parseLongFromTo(char[] digitChars, int offset, int to)
    Parses a `long` from a character range.
    Parameters:
      `digitChars` - the digit characters to parse
      `offset` - the inclusive range start
      `to` - the exclusive range end
    Returns:
      the parsed value

  - ### parseLong

    public static long parseLong(char[] digitChars)
    Parses a `long` from the supplied digit characters.
    Parameters:
      `digitChars` - the digit characters to parse
    Returns:
      the parsed value

  - ### parseJsonNumber

    public static Number parseJsonNumber(char[] buffer)
    Parses a JSON number from the supplied character array.
    Parameters:
      `buffer` - the character array containing the number
    Returns:
      the parsed `Number`

  - ### parseJsonNumber

    public static Number parseJsonNumber(char[] buffer, int from, int to)
    Parses a JSON number from a character range.
    Parameters:
      `buffer` - the character array containing the number
      `from` - the inclusive range start
      `to` - 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:
      `true` if 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:
      `true` if the code point is a structural delimiter

  - ### parseJsonNumber

    public static Number parseJsonNumber(char[] buffer, int from, int max, int[] size)
    Parses a JSON number and optionally reports the stopping index.
    Parameters:
      `buffer` - the character array containing the number
      `from` - the inclusive range start
      `max` - the exclusive scan limit
      `size` - optional single-element output array receiving the stopping index
    Returns:
      the parsed `Number`

  - ### parseJsonNumber

    public static Number parseJsonNumber(char[] buffer, int from, int max, int[] size, int maxNumberLength)
    Parses a JSON number and optionally reports the stopping index, bounding the length of the number token.
    Parameters:
      `buffer` - the character array containing the number
      `from` - the inclusive range start
      `max` - the exclusive scan limit
      `size` - optional single-element output array receiving the stopping index
      `maxNumberLength` - the maximum permitted token length; `0` or less disables the check
    Returns:
      the parsed `Number`
    Throws:
      `JsonException` - if the number token is longer than `maxNumberLength`

  - ### parseBigDecimal

    public static BigDecimal parseBigDecimal(char[] buffer)
    Parses a `BigDecimal` from 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 a `float` from a character range.
    Parameters:
      `buffer` - the character array to parse
      `from` - the inclusive range start
      `to` - the exclusive range end
    Returns:
      the parsed value

  - ### parseDouble

    public static double parseDouble(char[] buffer, int from, int to)
    Parses a `double` from a character range.
    Parameters:
      `buffer` - the character array to parse
      `from` - the inclusive range start
      `to` - 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 scan
      `index` - the index to start from
      `length` - 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 array
      `idx` - the index at which the number starts
      `len` - the exclusive scan limit
    Returns:
      a new array containing the number token

  - ### errorDetails

    public static String errorDetails(String message, char[] array, int index, int ch)
    Builds a human-readable parse error description for the current character position.
    Parameters:
      `message` - the high-level error message
      `array` - the source character array
      `index` - the failing index
      `ch` - the current character code
    Returns:
      the formatted diagnostic text

  - ### debugCharDescription

    public static String debugCharDescription(int c)
    Returns a debug string for a character code.
    Parameters:
      `c` - the character code to describe
    Returns:
      a printable character description