feat: remove diacritics

This commit is contained in:
henri2h 2022-04-05 20:38:55 +02:00
parent 7e0bcf5629
commit 758adff559
2 changed files with 18 additions and 3 deletions

View File

@ -6,6 +6,7 @@ import 'package:matrix/matrix.dart';
import 'package:vrouter/vrouter.dart'; import 'package:vrouter/vrouter.dart';
import 'package:fluffychat/pages/chat_list/chat_list_item.dart'; import 'package:fluffychat/pages/chat_list/chat_list_item.dart';
import 'package:fluffychat/utils/string_extension.dart';
import 'package:fluffychat/widgets/avatar.dart'; import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/contacts_list.dart'; import 'package:fluffychat/widgets/contacts_list.dart';
import 'package:fluffychat/widgets/default_app_bar_search_field.dart'; import 'package:fluffychat/widgets/default_app_bar_search_field.dart';
@ -68,9 +69,8 @@ class SearchView extends StatelessWidget {
rooms.removeWhere( rooms.removeWhere(
(room) => (room) =>
room.lastEvent == null || room.lastEvent == null ||
!room.displayname !room.displayname.toLowerCase().removeDiacritics().contains(
.toLowerCase() controller.controller.text.toLowerCase().removeDiacritics()),
.contains(controller.controller.text.toLowerCase()),
); );
const tabCount = 3; const tabCount = 3;
return DefaultTabController( return DefaultTabController(

View File

@ -0,0 +1,15 @@
extension StringCasingExtension on String {
String removeDiacritics() {
const withDia =
'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
const withoutDia =
'AAAAAAaaaaaaOOOOOOOooooooEEEEeeeeeCcDIIIIiiiiUUUUuuuuNnSsYyyZz';
String str = this;
for (int i = 0; i < withDia.length; i++) {
str = str.replaceAll(withDia[i], withoutDia[i]);
}
return str;
}
}