blob: b70e8c492b6c8dfdb44bc16b55b01fd784de8562 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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")
|