2021-04-10 06:28:12 +02:00
|
|
|
extension StringExtension on String {
|
|
|
|
/// Returns the string without any leading characters included in [characters]
|
|
|
|
String trimLeftAny(String characters) {
|
|
|
|
int i = 0;
|
|
|
|
while (i < length && characters.contains(this[i])) {
|
|
|
|
i += 1;
|
|
|
|
}
|
2021-09-15 08:58:06 +02:00
|
|
|
return substring(i);
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the string without any trailing characters included in
|
|
|
|
/// [characters]
|
|
|
|
String trimRightAny(String characters) {
|
|
|
|
int i = 0;
|
|
|
|
while (i < length && characters.contains(this[length - 1 - i])) {
|
|
|
|
i += 1;
|
|
|
|
}
|
2021-09-15 08:58:06 +02:00
|
|
|
return substring(0, length - i);
|
2021-04-10 06:28:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the string without any leading and trailing characters included in
|
|
|
|
/// [characters]
|
|
|
|
String trimAny(String characters) {
|
|
|
|
return trimLeftAny(characters).trimRightAny(characters);
|
|
|
|
}
|
|
|
|
}
|