From 543a1cd4d74aff3ca679097cf30176e69ffb3480 Mon Sep 17 00:00:00 2001 From: Luke Rogers Date: Wed, 4 Sep 2013 19:52:38 +1200 Subject: [PATCH] added alternate truncate method --- plugins/util/text.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugins/util/text.py b/plugins/util/text.py index 8e5c8a0..2d32cd6 100755 --- a/plugins/util/text.py +++ b/plugins/util/text.py @@ -95,6 +95,24 @@ def multiword_replace(text, wordDic): return rc.sub(translate, text) +def truncate_words(content, length=10, suffix='...'): + "Truncates a string after a certain number of words." + nmsg = content.split(" ") + out = None + x = 0 + for i in nmsg: + if x <= length: + if out: + out = out + " " + nmsg[x] + else: + out = nmsg[x] + x = x + 1 + if x <= length: + return out + else: + return out + suffix + + # from def truncate_str(content, length=100, suffix='...'): "Truncates a string after a certain number of chars."