]> de.git.xonotic.org Git - xonotic/xonstat.git/commitdiff
Merge pull request #2 from dmazary/master
authorantzucaro <azucaro@gmail.com>
Sun, 20 Nov 2011 00:40:37 +0000 (16:40 -0800)
committerantzucaro <azucaro@gmail.com>
Sun, 20 Nov 2011 00:40:37 +0000 (16:40 -0800)
Add function to utils.py to decode Quake's qfont into ascii

xonstat/util.py

index 4ef6c8097bb72da72759da1da034ce93fd7cafe1..b0b548100ad26cd8ede9b82e2f85b4efc3161c66 100755 (executable)
@@ -1,6 +1,56 @@
 import re
 from datetime import datetime
 
+# Map of special chars to ascii from Quake's console.c.
+qfont_table = [
+ '\0', '#',  '#',  '#',  '#',  '.',  '#',  '#',
+ '#',  '\t', '\n', '#',  ' ',  '\r', '.',  '.',
+ '[',  ']',  '0',  '1',  '2',  '3',  '4',  '5',
+ '6',  '7',  '8',  '9',  '.',  '<',  '=',  '>',
+ ' ',  '!',  '"',  '#',  '$',  '%',  '&',  '\'',
+ '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',
+ '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',
+ '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',
+ '@',  'A',  'B',  'C',  'D',  'E',  'F',  'G',
+ 'H',  'I',  'J',  'K',  'L',  'M',  'N',  'O',
+ 'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',
+ 'X',  'Y',  'Z',  '[',  '\\', ']',  '^',  '_',
+ '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
+ 'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
+ 'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
+ 'x',  'y',  'z',  '{',  '|',  '}',  '~',  '<',
+ '<',  '=',  '>',  '#',  '#',  '.',  '#',  '#',
+ '#',  '#',  ' ',  '#',  ' ',  '>',  '.',  '.',
+ '[',  ']',  '0',  '1',  '2',  '3',  '4',  '5',
+ '6',  '7',  '8',  '9',  '.',  '<',  '=',  '>',
+ ' ',  '!',  '"',  '#',  '$',  '%',  '&',  '\'',
+ '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',
+ '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',
+ '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',
+ '@',  'A',  'B',  'C',  'D',  'E',  'F',  'G',
+ 'H',  'I',  'J',  'K',  'L',  'M',  'N',  'O',
+ 'P',  'Q',  'R',  'S',  'T',  'U',  'V',  'W',
+ 'X',  'Y',  'Z',  '[',  '\\', ']',  '^',  '_',
+ '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',
+ 'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',
+ 'p',  'q',  'r',  's',  't',  'u',  'v',  'w',
+ 'x',  'y',  'z',  '{',  '|',  '}',  '~',  '<'
+]
+
+
+def qfont_decode(qstr=''):
+    """
+    Convert the qfont characters in a string to ascii.
+    """
+    chars = []
+    for c in qstr:
+        if c >= u'\ue000' and c <= u'\ue0ff':
+            c = qfont_table[ord(c) - 0xe000]
+        chars.append(c)
+    return ''.join(chars)
+
+
 def strip_colors(str=''):
     if str is None:
         str = ''