veilidchat/lib/tools/misc.dart
2024-06-06 07:49:42 -04:00

19 lines
424 B
Dart

extension StringExt on String {
(String, String?) splitOnce(Pattern p) {
final pos = indexOf(p);
if (pos == -1) {
return (this, null);
}
final rest = substring(pos);
var offset = 0;
while (true) {
final match = p.matchAsPrefix(rest, offset);
if (match == null) {
break;
}
offset = match.end;
}
return (substring(0, pos), rest.substring(offset));
}
}