Browse Source

added unescapeHtmlString

Darren Ranalli 16 years ago
parent
commit
23b4f51b43
1 changed files with 16 additions and 1 deletions
  1. 16 1
      direct/src/showbase/PythonUtil.py

+ 16 - 1
direct/src/showbase/PythonUtil.py

@@ -32,7 +32,7 @@ __all__ = ['enumerate', 'unique', 'indent', 'nonRepeatingRandomList',
 'pandaBreak','pandaTrace','formatTimeCompact','DestructiveScratchPad',
 'deeptype','getProfileResultString','StdoutCapture','StdoutPassthrough',
 'Averager', 'getRepository', 'formatTimeExact', 'startSuperLog', 'endSuperLog',
-'typeName', 'safeTypeName', 'histogramDict', ]
+'typeName', 'safeTypeName', 'histogramDict', 'unescapeHtmlString', ]
 
 import types
 import string
@@ -4009,6 +4009,21 @@ def histogramDict(l):
         d[e] += 1
     return d
 
+def unescapeHtmlString(s):
+    # converts %## to corresponding character
+    # replaces '+' with ' '
+    while 1:
+        try:
+            i = s.index('%')
+        except:
+            break
+        lastCharIndex = len(s)-1
+        if i <= lastCharIndex-2:
+            num = eval('0x' + s[i+1:i+3])
+            s = s[:i] + chr(num) + s[i+3:]
+    s = s.replace('+', ' ')
+    return s
+
 import __builtin__
 __builtin__.Functor = Functor
 __builtin__.Stack = Stack