From 51df58b29178141ee01cb381b1393a98ddb271aa Mon Sep 17 00:00:00 2001 From: Etoh Date: Wed, 26 Apr 2017 20:16:57 +0100 Subject: [PATCH] Refactor/simplify truncateText --- syncplay/utils.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/syncplay/utils.py b/syncplay/utils.py index b4d6b34..4ce630f 100644 --- a/syncplay/utils.py +++ b/syncplay/utils.py @@ -172,16 +172,11 @@ def blackholeStdoutForFrozenWindow(): def truncateText(unicodeText, maxLength): try: - unicodeText = unicodedata.normalize('NFC', unicodeText) + unicodeText = unicodeText.decode('utf-8') except: pass try: - maxSaneLength= maxLength*5 - 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 + return(unicode(unicodeText.encode("utf-8"), "utf-8", errors="ignore")[:maxLength]) except: pass return ""