Repository navigation
Expand file tree
/
Copy pathfuzzystring.py
More file actions
51 lines (42 loc) · 1.5 KB
/
Copy pathfuzzystring.py
File metadata and controls
51 lines (42 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import unicodedata
class FuzzyString(str):
def _nc(self, text):
return unicodedata.normalize("NFKD", text.casefold())
def __init__(self, intext):
self.intext = intext
def __eq__(self, other):
return self._nc(self.intext.lower()) == self._nc(other.lower())
def __ne__(self,other):
return self.intext.lower() != other.lower()
def __lt__(self, other):
return self.intext.lower() < other.lower()
def __gt__(self,other):
return self.intext.lower() > other.lower()
def __ge__(self,other):
return self.intext.lower() >= other.lower()
def __le__(self,other):
return self.intext.lower() <= other.lower()
def __contains__(self, other):
return self._nc(other.lower()) in self._nc(self.intext.lower())
def __add__(self, other):
return FuzzyString("".join([self.lower(),other]))
a=FuzzyString('abc')
b=FuzzyString('BCD')
greeting = FuzzyString('Hey TREY!')
assert (greeting == 'hey Trey!') == True
assert ( greeting == 'heyTrey') == False
assert ( greeting != 'heyTrey') == True
o_word = FuzzyString('Octothorpe')
assert ('hashtag' < o_word) == True
assert ('hashtag' > o_word) == False
tokyo = FuzzyString("tokyo")
toronto = FuzzyString("TORONTO")
assert (tokyo < toronto) == True
assert (toronto < tokyo) == False
apple = FuzzyString('Apple')
assert (apple >= "animal")
ss = FuzzyString('ss')
assert('\u00df' == ss)
e = FuzzyString('\u00e9')
assert('\u0065\u0301' == e)
assert('\u0301' in e)