def iterchars(text):
# type: (str) -> Sequence[str]
idx = 0
chars = []
while idx < len(text):
c = text[idx]
if ord(c) >= 0x100:
highchar = True
if ((0xD800 <= ord(c) <= 0xDBFF) and (idx < len(text) - 1) and
(0xDC00 <= ord(text[idx + 1]) <= 0xDFFF)):
c = text[idx:idx + 2]
# Skip the other half of the lead and trail surrogate
idx += 1
else:
highchar = False
idx += 1
# Add every character except only one half of a surrogate pair.
if not (highchar and len(c) == 1 and 0xD800 <= ord(c) <= 0xDFFF):
chars.append(c)
return chars
评论列表
文章目录