def iternext(self):
"""
Iterate through characters of the string.
Count escaped l, L, c, C, E, N, p, P, backslash as a single char.
"""
if self.index > self.max_index:
raise StopIteration
char = self.string[self.index:self.index + 1]
if char == self._b_slash:
m = self._re_search_ref.match(self.string[self.index + 1:])
if m:
ref = m.group(0)
if len(ref) == 1 and ref in self._long_search_refs:
if ref == self._unicode_name:
raise SyntaxError('Format for Unicode name is \\N{name}!')
elif ref == self._uni_prop:
raise SyntaxError('Format for Unicode property is \\p{property}!')
elif ref == self._inverse_uni_prop:
raise SyntaxError('Format for inverse Unicode property is \\P{property}!')
char += m.group(1) if m.group(1) else m.group(2)
elif char == self._ls_bracket:
m = self._re_posix.match(self.string[self.index:])
if m:
char = m.group(0)
self.index += len(char)
self.current = char
return self.current
# Templates
评论列表
文章目录