5
5
import collections
6
6
import os
7
7
from typing import Any , List , Optional , Union
8
+ import unicodedata
8
9
9
10
from . import constants
10
11
@@ -110,7 +111,7 @@ def which(editor: str) -> Optional[str]:
110
111
111
112
112
113
def is_text_file (file_path : str ) -> bool :
113
- """Returns if a file contains only ASCII or UTF-8 encoded text
114
+ """Returns if a file contains only ASCII or UTF-8 encoded text.
114
115
115
116
:param file_path: path to the file being checked
116
117
:return: True if the file is a text file, False if it is binary.
@@ -147,8 +148,8 @@ def is_text_file(file_path: str) -> bool:
147
148
148
149
149
150
def remove_duplicates (list_to_prune : List ) -> List :
150
- """
151
- Removes duplicates from a list while preserving order of the items
151
+ """Removes duplicates from a list while preserving order of the items.
152
+
152
153
:param list_to_prune: the list being pruned of duplicates
153
154
:return: The pruned list
154
155
"""
@@ -159,10 +160,19 @@ def remove_duplicates(list_to_prune: List) -> List:
159
160
return list (temp_dict .keys ())
160
161
161
162
162
- def alphabetical_sort (list_to_sort : List [str ]) -> List [str ]:
163
+ def norm_fold (astr : str ) -> str :
164
+ """Normalize and casefold Unicode strings for saner comparisons.
165
+
166
+ :param astr: input unicode string
167
+ :return: a normalized and case-folded version of the input string
163
168
"""
164
- Sorts a list of strings alphabetically
169
+ return unicodedata .normalize ('NFC' , astr ).casefold ()
170
+
171
+
172
+ def alphabetical_sort (list_to_sort : List [str ]) -> List [str ]:
173
+ """Sorts a list of strings alphabetically.
174
+
165
175
:param list_to_sort: the list being sorted
166
176
:return: the sorted list
167
177
"""
168
- return sorted (list_to_sort , key = str . casefold )
178
+ return sorted (list_to_sort , key = norm_fold )
0 commit comments