Files
smooth-app/packages/smooth_app/lib/helpers/strings_helper.dart
monsieurtanuki fd868c7783 fix: 3723 - now always replaces decimal separator for number format (#3734)
* Revert "feat: 3585 - upgrade to flutter 3.7 (#3666)"

This reverts commit ad46236bdf77afea18b12cc69b3ee64a6752ee73.

* fix: 3723 - now always replaces decimal separator for number format

Impacted files:
* `strings_helper.dart`: removed now useless methods
* `text_input_formatters_helper.dart`: now works in all cases, regardless of the presence of group separator in the target language, given that we don't use group separators in our decimal number formats anyway

* fix: 3723 - unrelated localization fix

Impacted file:
* `app_ar.arb`
2023-02-23 11:05:28 +01:00

45 lines
1.1 KiB
Dart

extension StringExtensions on String {
/// Returns a list containing all positions of a [charCode]
/// By default, the case is taken into account.
/// Set [ignoreCase] to true, to disable the case verification.
List<int> indexesOf(
String charCode, {
bool ignoreCase = false,
}) {
assert(charCode.length == 1);
if (ignoreCase) {
charCode = charCode.toLowerCase();
}
final List<int> positions = <int>[];
int i = 0;
for (; i != length; i++) {
if ((ignoreCase && this[i].toLowerCase() == charCode) ||
this[i] == charCode) {
positions.add(i);
}
}
return positions;
}
/// Removes a character by giving its position
String removeCharacterAt(int position) {
assert(position >= 0 && position < length);
return substring(0, position) + substring(position + 1);
}
String replaceAllIgnoreFirst(Pattern from, String replace) {
bool isFirst = true;
return replaceAllMapped(from, (Match match) {
if (isFirst) {
isFirst = false;
return match.input.substring(match.start, match.end);
} else {
return replace;
}
});
}
}