Helper class for performing simple parsing tasks for strings.
sealed class
|
Parse
|
Calling ToString will return the remaining text, but will not modify the state of the Parse object.
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 := '-' | '+' ;
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. |
Returns the number of remaining characters in the input string.
public
property
|
Remaining
{
get
}
|
||
type
|
string
|
||
value
|
|
The number of remaining characters. |
Decrements the parse position.
public
method
|
Back
()
|
Begins to parse the given input text.
public
method
|
Begin
(string text)
|
||
type
|
Parse
|
||
params
|
text
|
[not-null]
|
The input text. |
returns
|
|
this |
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 .
|
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.
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:
integer-10
rule.
integer-16
rule.
See also:
Format.ThisIntExceptions:
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:
IntegerExceptions:
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.
|
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.
|
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.ThisNumExceptions:
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:
NumberExceptions:
float
of
ParseGrammar.
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:
Skips all coming non whitespaces.
public
method
|
SkipNonWhitespace
()
|
Skips all coming whitespaces.
public
method
|
SkipWhitespace
()
|
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
|
|
The created Parse object. |
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. |
public
override
method
|
ToString
()
|
||
type
|
string
|