mirror of
https://github.com/openfoodfacts/smooth-app.git
synced 2025-08-14 02:30:54 +08:00

* 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`
45 lines
1.1 KiB
Dart
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;
|
|
}
|
|
});
|
|
}
|
|
}
|