parse static method
- @Since.new("3.0")
Parsessource as an, optionally case-insensitive, boolean literal.
IfcaseSensitive istrue, which is the default,the only accepted inputs are the strings"true" and"false",which returns the resultstrue andfalse respectively.
IfcaseSensitive isfalse, any combination of upper and lower caseASCII letters in the words"true" and"false" are accepted,as if the input was first lower-cased.
Throws aFormatException if thesource string does not containa valid boolean literal.
Rather than throwing and immediately catching theFormatException,instead usetryParse to handle a potential parsing error.
Example:
print(bool.parse('true')); // trueprint(bool.parse('false')); // falseprint(bool.parse('TRUE')); // throws FormatExceptionprint(bool.parse('TRUE', caseSensitive: false)); // trueprint(bool.parse('FALSE', caseSensitive: false)); // falseprint(bool.parse('NO')); // throws FormatExceptionprint(bool.parse('YES')); // throws FormatExceptionprint(bool.parse('0')); // throws FormatExceptionprint(bool.parse('1')); // throws FormatExceptionImplementation
@Since("3.0")external static bool parse(String source, {bool caseSensitive = true});