Options
All
  • Public
  • Public/Protected
  • All
Menu

Class StringScanner

Hierarchy

  • StringScanner

Index

Constructors

Methods Accessing Match Data

Methods Accessing Scanner State

Methods Looking Ahead

Methods Modifying Scanner State

Methods Scanning and Skipping

Constructors

  • Create a new StringScanner containing the given string.

    Parameters

    • source: Stringable

      The string to be scanned. If not a string, it will be converted using toSAtring()

    Returns StringScanner

Accessing Match Data Methods

  • getCapture(index: number): string
  • Returns the indexth capture from the most recent match (or null if there is no recent match).

    Parameters

    • index: number

    Returns string

  • getMatch(): string
  • Returns the most recently matched portion of the source string (or null if there is no recent match).

    Returns string

  • getPostMatch(): undefined | string
  • Returns the portion of the source string immediately following the most recent match. (Returns null if there is no recent match.)

    Returns undefined | string

  • getPreMatch(): undefined | string
  • The getPreMatch, getMatch, getPostMatch and getCapture methods provide information about the most recent match.


    Returns the portion of the source string leading up to, but not including, the most recent match. (Returns null if there is no recent match.)

    Returns undefined | string

Accessing Scanner State Methods

  • getPosition(): number
  • Returns the scanner's position. In the reset position, this value is zero. In the terminated position, this value is the length of the source string.

    Returns number

  • getRemainder(): string
  • Returns the portion of the source string from the scanner's position onward.

    Returns string

  • getSource(): string
  • The getSource, getRemainder, getPosition and hasTerminated methods provide information about the scanner's source string and position.


    Returns the scanner's source string.

    Returns string

  • hasTerminated(): boolean
  • Checks to see if the scanner has reached the end of the string.

    Returns boolean

Looking Ahead Methods

  • check(regexp: RegExp): string
  • The check, checkUntil and peek methods look for matching strings without advancing the scanner's position.


    Checks to see if regexp can be matched at the current position and returns the matched string without advancing the scanner's position, or returns null if there is no match.

    Parameters

    • regexp: RegExp

    Returns string

  • checkUntil(regexp: RegExp): string
  • Checks to see if regexp can be matched at or after the current position. Returns the portion of the source string after the current position up to and including the end of the match without advancing the scanner's position, or returns null if there is no match.

    Parameters

    • regexp: RegExp

    Returns string

  • peek(length?: number): string
  • Returns the next length characters after the current position. If called without a length, returns the next character. The scanner's position is not advanced.

    Parameters

    • length: number = 1

    Returns string

Modifying Scanner State Methods

  • concat(string: string): void
  • Appends string to the scanner's source string. The scanner's position is not affected.

    Parameters

    • string: string

    Returns void

  • reset(): void
  • The reset, terminate, concat and unscan methods let you change the state of the scanner.


    Resets the scanner back to its original position and clears its match data.

    Returns void

  • terminate(): void
  • Advances the scanner position to the end of the string and clears its match data.

    Returns void

  • unscan(): string
  • Sets the scanner's position to its previous position and clears its match data. Only one previous position is stored. Throws an exception if there is no previous position.

    Returns string

Scanning and Skipping Methods

  • scan(regexp: RegExp): string
  • The scan, scanUntil, scanChar, skip, and skipUntil methods look for matching strings and advance the scanner's position. The scan methods return the matched string; the skip methods return the number of characters by which the scan position advanced.


    Matches regexp at the current position. Returns the matched string and advances the scanner's position, or returns null if there is no match.

    Parameters

    • regexp: RegExp

    Returns string

  • scanChar(): string
  • Scans one character, returns it, and advances the scanner's position.

    Returns string

  • scanUntil(regexp: RegExp): string
  • Matches regexp at or after the current position. Returns the portion of the source string after the scanner's position up to and including the end of the match and advances the scanner's position, or returns null if there is no match.

    Parameters

    • regexp: RegExp

    Returns string

  • skip(regexp: RegExp): undefined | number
  • Skips over the given regexp at the current position. Returns the length of the matched string and advances the scanner's position, or returns null if there is no match.

    Parameters

    • regexp: RegExp

    Returns undefined | number

  • skipUntil(regexp: RegExp): undefined | number
  • Skips over the given regexp at or after the current position. Returns the length of the string up to and including the end of the match and advances the scanner's position, or returns null if there is no match.

    Parameters

    • regexp: RegExp

    Returns undefined | number

Generated using TypeDoc