Refactor/simplify truncateText
This commit is contained in:
parent
d7b5abc577
commit
51df58b291
@ -172,16 +172,11 @@ def blackholeStdoutForFrozenWindow():
|
|||||||
|
|
||||||
def truncateText(unicodeText, maxLength):
|
def truncateText(unicodeText, maxLength):
|
||||||
try:
|
try:
|
||||||
unicodeText = unicodedata.normalize('NFC', unicodeText)
|
unicodeText = unicodeText.decode('utf-8')
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
maxSaneLength= maxLength*5
|
return(unicode(unicodeText.encode("utf-8"), "utf-8", errors="ignore")[:maxLength])
|
||||||
if len(unicodeText) > maxSaneLength:
|
|
||||||
unicodeText = unicode(unicodeText.encode("utf-8")[:maxSaneLength], "utf-8", errors="ignore")
|
|
||||||
while len(unicodeText) > maxLength:
|
|
||||||
unicodeText = unicode(unicodeText.encode("utf-8")[:-1], "utf-8", errors="ignore")
|
|
||||||
return unicodeText
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user