work for improvements

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-09-05 20:10:13 -04:00
parent 0c258bdec5
commit 3a67c6eb10
1 changed files with 22 additions and 9 deletions

View File

@ -95,6 +95,23 @@ width_map = {
'N': 'Narrow', 'N': 'Narrow',
} }
def hex2(i):
h = hex(i)[2:]
if len(h) % 2 == 1:
return '0' + h
else:
return h
def uniesc(i):
return '\\x' + hex2(i)
def unichar(s):
s = "u'" + s + "'"
try:
return eval(s, {}, {})
except:
return None
def unicodeget(u, fname, fallback): def unicodeget(u, fname, fallback):
try: try:
f = getattr(unicodedata, fname) f = getattr(unicodedata, fname)
@ -127,11 +144,9 @@ Normalize %s
Numeric %s''' Numeric %s'''
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
s = "u'" + vargs['code'] + "'" s = "u'" + vargs['code'] + "'"
try: u = unichar(vargs['code'])
u = eval(s, {}, {}) if u is None:
w.insert_string_at_cursor(u) w.set_error("invalid: %s" % vargs['code'])
except:
w.set_error("invalid: %s" % vargs['data'])
return return
a = unicodeget(u, 'category', '??') a = unicodeget(u, 'category', '??')
@ -184,8 +199,6 @@ class Utf8Insert(Method):
args = [arg("data", t=type(""), p="UTF-8 Data: ", h="the UTF-8 data to use")] args = [arg("data", t=type(""), p="UTF-8 Data: ", h="the UTF-8 data to use")]
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
s = "u'" + vargs['data'] + "'" s = "u'" + vargs['data'] + "'"
try: u = unichar(vargs['code'])
u = eval(s, {}, {}) if u is None:
w.insert_string_at_cursor(u)
except:
w.set_error("invalid: %s" % vargs['data']) w.set_error("invalid: %s" % vargs['data'])