From: Ant Zucaro Date: Sun, 8 May 2011 16:20:12 +0000 (-0400) Subject: Add a file for general utility functions X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=2a5be1fcd70d63e52adc4611caac43c81dfa625d;p=xonotic%2Fxonstat.git Add a file for general utility functions --- diff --git a/xonstat/util.py b/xonstat/util.py new file mode 100644 index 0000000..4f0b0da --- /dev/null +++ b/xonstat/util.py @@ -0,0 +1,26 @@ +import re + +def strip_colors(str=None): + str = re.sub(r'\^x\w\w\w', '', str) + str = re.sub(r'\^\d', '', str) + return str + +def html_colors(str=None): + orig = str + str = re.sub(r'\^x(\w)(\w)(\w)', + "", str) + str = re.sub(r'\^1', "", str) + str = re.sub(r'\^2', "", str) + str = re.sub(r'\^3', "", str) + str = re.sub(r'\^4', "", str) + str = re.sub(r'\^5', "", str) + str = re.sub(r'\^6', "", str) + str = re.sub(r'\^7', "", str) + str = re.sub(r'\^8', "", str) + str = re.sub(r'\^9', "", str) + str = re.sub(r'\^0', "", str) + + for span in range(len(re.findall(r'\^x\w\w\w|\^\d', orig))): + str += "" + + return str