mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-19 00:22:50 +01:00
Fix normalizeWhitespace to support Unicode.
This commit is contained in:
parent
a3cf9f8b45
commit
7e002ed2a2
@ -61,12 +61,16 @@ def rsplit(s, sep=None, maxsplit=-1):
|
|||||||
|
|
||||||
def normalizeWhitespace(s, removeNewline=True):
|
def normalizeWhitespace(s, removeNewline=True):
|
||||||
"""Normalizes the whitespace in a string; \s+ becomes one space."""
|
"""Normalizes the whitespace in a string; \s+ becomes one space."""
|
||||||
s = str(s)
|
replace_fn = lambda x, y, z: str.replace(x, y, z)
|
||||||
|
if isinstance(s, unicode):
|
||||||
|
replace_fn = lambda x, y, z: unicode.replace(x, y, z)
|
||||||
|
else:
|
||||||
|
s = str(s)
|
||||||
if removeNewline:
|
if removeNewline:
|
||||||
s = str.replace(s, '\n', '')
|
s = replace_fn(s, '\n', '')
|
||||||
s = str.replace(s, '\t', ' ')
|
s = replace_fn(s, '\t', ' ')
|
||||||
while ' ' in s:
|
while ' ' in s:
|
||||||
s = str.replace(s, ' ', ' ')
|
s = replace_fn(s, ' ', ' ')
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def distance(s, t):
|
def distance(s, t):
|
||||||
|
Loading…
Reference in New Issue
Block a user