engine: Add AddressSpace.memcpy() function.
[ScratchABit.git] / utils.py
blobe90dddbd1630fd3d87507a4c55764dfce836e00c
1 import string
4 def bidict(d):
5 for k in list(d.keys()):
6 v = d[k]
7 d[v] = k
8 return d
11 def get_word_at_pos(str, pos):
12 if pos < 0:
13 return None
14 if pos >= len(str):
15 pos = len(str) - 1
16 word_chars = string.ascii_letters + string.digits + "._+"
17 if str[pos] not in word_chars:
18 return None
19 beg = pos
20 while beg >= 1 and str[beg - 1] in word_chars:
21 beg -= 1
22 end = pos
23 while end < len(str) - 1 and str[end + 1] in word_chars:
24 end += 1
25 return str[beg:end + 1]