TINMAN 3D / REALTIME TERRAIN
Software Development Kit - User Manual

class Parse in Tinman.Core.Parsing

Helper class for performing simple parsing tasks for strings.

sealed class Parse  

Remarks

Calling ToString will return the remaining text, but will not modify the state of the Parse object.

Public / Constants

ParseGrammar

The grammar of this class.

public static readonly field ParseGrammar
type Grammar

Remarks:

!float     := sign? (decimal exponent? | infinity) | notanumber ;
!integer-10:= sign? digit+ ;
!integer-16:= (digit | 'a'..'f' | 'A'..'F')+ ;

decimal    := digit+ ('.' digit*)? | '.' digit+ ;
exponent   := @'E' sign? digit+ ;
infinity   := @'Inf' ;
notanumber := @'NaN' ;

digit      := '0'..'9' ;
sign       := '-' | '+' ;

Public / Attributes

IsEof

Has the end of input been reached?

public property IsEof { get }
type bool
value true if the end of input has been reached, false if not.

Remaining

Returns the number of remaining characters in the input string.

public property Remaining { get }
type string
value [>=0] The number of remaining characters.

Public / Methods

Back

Decrements the parse position.

public method Back ()

Begin

Begins to parse the given input text.

public method Begin (string text)
type Parse
params text [not-null] The input text.
returns [not-null] this

Consume

Consume the next n input characters.

public method Consume (int32 n = 1)
params n [>=0] The number of input characters to consume. Defaults to 1.

Follows

Does the given string match the input that follows?

public method Follows (string s)
type bool
params s [not-null] The string.
returns true if the following input matches, false if not.

Remarks:

The current parse position is not modified by this method.

Integer

Parses an integer number.

public method Integer (FormatFlags numberBase = FormatFlags.NumberBaseDecimal)
type int64
params numberBase The number base. Defaults to NumberBaseDecimal.
returns The number value.

Remarks:

Valid input strings are defined by the following rules of ParseGrammar:

See also:

Format.ThisInt

Exceptions:


Parses the given string as an integer number.

public static method Integer (string value, FormatFlags numberBase = FormatFlags.NumberBaseDecimal)
type int64
params value The string to parse.
  numberBase The number base. Defaults to NumberBaseDecimal.
returns The integer number.

See also:

Integer
Format.ThisInt

Exceptions:

LookAhead

Peeks at the following input character.

public method LookAhead (int32 idx = 0)
type int32
params idx [>=0] Index of character to peek, relative to current parse position. Defaults to 0.
returns The character or -1 if the end of the input data has been reached.

Next

Reads the next character from the current line and increments the parse position.

public method Next ()
type int32
returns The next character or -1 if the end of the input data has been reached.

Number

Parses a floating-point number.

public method Number ()
type float64
returns The number value.

Remarks:

Valid input strings are defined by the float rule of ParseGrammar.

See also:

Format.ThisNum

Exceptions:


Parses the given string as a floating-point number.

public static method Number (string value)
type float64
params value The string to parse.
returns The floating-point number.

See also:

Number
Format.ThisNum

Exceptions:

NumberLenient

Parses the given string as a floating-point number.

public static method NumberLenient (string value, float64 defaultValue = 0)
type float64
params value Some number string.
  defaultValue The default value to return if value is invalid.
returns The parsed number.

Remarks:

The method applies the following logic in order parse number strings in a lenient manner:

  1. All whitespace characters are stripped from value.
  2. All ',' characters are stripped iff they occur twice or more.
  3. All '.' characters are stripped iff they occur twice or more.
  4. If either '.' or ',' is present, use it as decimal separator and parse the number.
  5. Otherwise both '.' and ',' are present; use each as decimal separator, parse the number twice and use the number that has the larger absolute value.

SkipNonWhitespace

Skips all coming non whitespaces.

public method SkipNonWhitespace ()

SkipWhitespace

Skips all coming whitespaces.

public method SkipWhitespace ()

Text

Returns a Parse object for the given input string.

public static method Text (string text)
type Parse
params text [not-null] The input string.
returns [not-null] The created Parse object.

Token

Tries to consume the given text token.

public method Token (string token, bool caseSensitive = true)
type bool
params token [not-null] The text token.
  caseSensitive Match the text token in a case-sensitive manner? Defaults to true.
returns true if the token has been matched, false if not.

ToString

public override method ToString ()
type string