def u_to_utf8(dfa, base=0):
c = itertools.count(base)
transitions = dfa.transitions
for src, trans in iteritems(transitions):
trans = transitions[src]
for label, dest in list(iteritems(trans)):
if label is EPSILON:
continue
elif label is ANY:
raise Exception
else:
assert isinstance(label, text_type)
label8 = label.encode("utf8")
for i, byte in enumerate(label8):
if i < len(label8) - 1:
st = next(c)
dfa.add_transition(src, byte, st)
src = st
else:
dfa.add_transition(src, byte, dest)
del trans[label]
评论列表
文章目录