summaryrefslogtreecommitdiff
path: root/scripts/asmquote.py
blob: cfc1440897ed108d569a6c7d50d4b8237e9ce081 (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
asmProblemBytes = ['\x00', '\x09', '\x0A', '\x22']
def asmQuote(t):
	result = ""
	quoted = False
	if t[0] in asmProblemBytes:
		result = '{0}'.format(ord(t[0]))
	else:
		result = '"' + t[0]
		quoted = True
	t = t[1:]

	while len(t):
		if quoted and t[0] in asmProblemBytes:
			result += '",{0}'.format(ord(t[0]))
			quoted = False
		elif quoted:
			result += t[0]
		elif t[0] in asmProblemBytes:
			result += ',{0}'.format(ord(t[0]))
			quoted = False
		else:
			result += ',"' + t[0]
			quoted = True
		t = t[1:]
	if quoted:
		result += '"'
	return result