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',
}
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):
try:
f = getattr(unicodedata, fname)
@ -127,11 +144,9 @@ Normalize %s
Numeric %s'''
def _execute(self, w, **vargs):
s = "u'" + vargs['code'] + "'"
try:
u = eval(s, {}, {})
w.insert_string_at_cursor(u)
except:
w.set_error("invalid: %s" % vargs['data'])
u = unichar(vargs['code'])
if u is None:
w.set_error("invalid: %s" % vargs['code'])
return
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")]
def _execute(self, w, **vargs):
s = "u'" + vargs['data'] + "'"
try:
u = eval(s, {}, {})
w.insert_string_at_cursor(u)
except:
u = unichar(vargs['code'])
if u is None:
w.set_error("invalid: %s" % vargs['data'])