+ def get_target_region(self, text, pos):
+ ch = text[pos:pos + 1]
+ rlen = 0
+ llen = 0
+ while rlen <= 4 and self.char_util.is_hex_char(ch):
+ rlen += 1
+ if pos + rlen >= len(text): break
+ ch = text[(pos + rlen):(pos + rlen + 1)]
+ if rlen >= 1 and rlen < 5:
+ while rlen + llen <= 4 and pos - llen > 0:
+ ch = text[(pos - llen - 1):(pos - llen)]
+ if not self.char_util.is_hex_char(ch): break
+ llen += 1
+ ret = (pos - llen, pos + rlen)
+ if ret == (pos, pos): return (pos, pos + 1)
+ return ret
+
+class CharUtil:
+ def is_hex_char(self, char):
+ return (char >= '0' and char <= '9') or \
+ (char >= 'a' and char <= 'f') or \
+ (char >= 'A' and char <= 'F')
+
+ def get_unichar(self, buf):
+ if len(buf) <= 1: return buf
+
+ return unichr(int(buf, 16))
+