regexpToFunction function
Implementation
MatchFunction regexpToFunction(
RegExp re,
List<Key> keys,
String Function(String?, dynamic) decode,
// options: RegexpToFunctionOptions = {}
) {
// final { decode = (x: string) => x } = options;
return (String pathname) {
final m = re.firstMatch(pathname);
if (m == null) {
return null;
}
// final { 0: path, index } = m;
final path = m.group(0)!;
final index = m.start;
final params = {};
for (int i = 1; i < m.groupCount; i++) {
// tslint:disable-next-line
if (m[i] == null) {
continue;
}
final key = keys[i - 1];
if (key.modifier == '*' || key.modifier == '+') {
params[key.name] = m[i]?.split(key.prefix + key.suffix).map((value) {
return decode(value, key);
});
} else {
params[key.name] = decode(m[i], key);
}
}
return Match(
index: index,
path: path,
params: params,
);
};
}