summaryrefslogtreecommitdiff
path: root/strfile.py
diff options
context:
space:
mode:
Diffstat (limited to 'strfile.py')
-rw-r--r--strfile.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/strfile.py b/strfile.py
new file mode 100644
index 0000000..b70e8c4
--- /dev/null
+++ b/strfile.py
@@ -0,0 +1,30 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+import os, re
+
+lotr_str_regex = re.compile(r'([A-Z]*\:.*?)\"(.*?)\"(?:.*?)END',re.DOTALL)
+
+def dict_parse(rawdata):
+ global lotr_str_regex
+ rawdata = rawdata.decode("latin-1")
+
+ dictionary = {}
+
+ for match, string in lotr_str_regex.findall(rawdata):
+ match = match.strip()
+ string = string.strip()
+
+ dictionary[match] = string
+ return dictionary
+
+def dict_gen(dictionary, fp):
+ for match in dictionary:
+ fp.write("%s\n\"%s\"\nEND\n\n" % (match.encode('latin-1'),
+ dictionary[match].encode('latin-1')))
+
+def escape(text):
+ return text.replace("\n", "\\n")
+
+def unescape(text):
+ return text.replace("\\n", "\n")