summaryrefslogtreecommitdiff
path: root/strfile.py
blob: e80f7095d4538092624bc15f5bced1038258e0a3 (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-Za-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")