parse static method
- @Since("3.0")
Parses source
as an, optionally case-insensitive, boolean literal.
If caseSensitive
is true
, which is the default,
the only accepted inputs are the strings "true"
and "false"
,
which returns the results true
and false
respectively.
If caseSensitive
is false
, any combination of upper and lower case
ASCII letters in the words "true"
and "false"
are accepted,
as if the input was first lower-cased.
Throws a FormatException if the source
string does not contain
a valid boolean literal.
Rather than throwing and immediately catching the FormatException, instead use tryParse to handle a potential parsing error.
Example:
print(bool.tryParse('true')); // true
print(bool.tryParse('false')); // false
print(bool.tryParse('TRUE')); // throws FormatException
print(bool.tryParse('TRUE', caseSensitive: false)); // true
print(bool.tryParse('FALSE', caseSensitive: false)); // false
print(bool.tryParse('NO')); // throws FormatException
print(bool.tryParse('YES')); // throws FormatException
print(bool.tryParse('0')); // throws FormatException
print(bool.tryParse('1')); // throws FormatException
Implementation
@Since("3.0")
external static bool parse(String source, {bool caseSensitive = true});