TokenSet.fromString constructor
TokenSet.fromString(
- String str
Implementation
factory TokenSet.fromString(String str) {
var node = TokenSet();
TokenSet root = node;
/*
* Iterates through all characters within the passed string
* appending a node for each character.
*
* When a wildcard character is found then a self
* referencing edge is introduced to continually match
* any number of any characters.
*/
for (var i = 0, len = str.length; i < len; i++) {
var char = str[i];
bool isFinal = (i == len - 1);
if (char == "*") {
node.edges[char] = node;
node.isFinal = isFinal;
} else {
var next = TokenSet();
next.isFinal = isFinal;
node.edges[char] = next;
node = next;
}
}
return root;
}