patternIgnoreCase function
Returns a parser that accepts a single character of a given case-insensitive character set provided as a string.
Characters match themselves. A dash -
between two characters matches the
range of those characters. A caret ^
at the beginning negates the pattern.
For example, the parser patternIgnoreCase('aoU')
accepts the character
'a', 'o', 'u' and 'A', 'O', 'U', and fails for any other input. The parser
patternIgnoreCase('a-c')
accepts 'a', 'b', 'c' and 'A', 'B', 'C'; and
fails for any other character. The parser `patternIgnoreCase('^A') accepts
any character, but fails for the characters 'a' or 'A'.
Implementation
Parser<String> patternIgnoreCase(String element, [String? message]) {
final isNegated = element.startsWith('^');
if (isNegated) {
element = element.substring(1);
}
final isDashed = element.endsWith('-');
if (isDashed) {
element = element.substring(0, element.length - 1);
}
return pattern(
'${isNegated ? '^' : ''}'
'${element.toLowerCase()}${element.toUpperCase()}'
'${isDashed ? '-' : ''}',
message);
}