removeDiacritics method
Removes common latin diacritics for normalized matching/search.
Implementation
String removeDiacritics() {
var value = this;
const groups = <String, String>{
r'[àáâãäåāăą]': 'a',
r'[çćĉċč]': 'c',
r'[ďđ]': 'd',
r'[èéêëēĕėęě]': 'e',
r'[ƒ]': 'f',
r'[ĝğġģ]': 'g',
r'[ĥħ]': 'h',
r'[ìíîïĩīĭįı]': 'i',
r'[ĵ]': 'j',
r'[ķĸ]': 'k',
r'[ĺļľŀł]': 'l',
r'[ñńņňʼnŋ]': 'n',
r'[òóôõöøōŏő]': 'o',
r'[ŕŗř]': 'r',
r'[śŝşš]': 's',
r'[ţťŧ]': 't',
r'[ùúûüũūŭůűų]': 'u',
r'[ŵ]': 'w',
r'[ýÿŷ]': 'y',
r'[źżž]': 'z',
r'[æ]': 'ae',
r'[œ]': 'oe',
r'[ß]': 'ss',
};
groups.forEach((pattern, replacement) {
final regex = RegExp(pattern, caseSensitive: false);
value = value.replaceAllMapped(regex, (match) {
final source = match.group(0)!;
final isUppercase = source == source.toUpperCase();
return isUppercase ? replacement.toUpperCase() : replacement;
});
});
return value;
}