CharacterClass.literal constructor

CharacterClass.literal(
  1. String literal
)

Given a literal character, matches the same character with attaching a backslash to escape possibility of conflicts with existing literals used by other matching operator.

Example:

// Matches a square opening bracket
var cmp = CharacterClass.literal("[",);

Implementation

factory CharacterClass.literal(String literal,) {
  literal = literal.trim();
  if (literal.isEmpty) {
    throw ArgumentError.value(literal, "Literal", "Must not be empty",);
  }
  return CharacterClass._raw("\\${literal[0]}",);
}