diff options
author | Kevin Chabowski <kevin@kch42.de> | 2011-05-19 21:41:56 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2011-05-19 21:41:56 +0200 |
commit | 012646f3f726c37d84a0de9554db3a1d80145274 (patch) | |
tree | 82e4bedba40299daf68f31baf442cd788aebe45d /strfile.py | |
download | dotstr_edit-012646f3f726c37d84a0de9554db3a1d80145274.tar.gz dotstr_edit-012646f3f726c37d84a0de9554db3a1d80145274.tar.bz2 dotstr_edit-012646f3f726c37d84a0de9554db3a1d80145274.zip |
Initial commit (uncoupled from sum2tools)
Diffstat (limited to 'strfile.py')
-rw-r--r-- | strfile.py | 30 |
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") |