def _first_char(self, data):
"""Return the first character of data (in bibtex's sense)."""
# XXX Should this be pulled out as some generic algorithm?
pos = 0
depths = self.__depth(data)
while True:
if pos == len(data):
return ''
elif data[pos].isalpha():
return data[pos]
elif data.startswith('{\\', pos):
# Special character
pos += 1
m = re.compile(r'\\[a-zA-Z]+').match(data, pos)
if m and m.group() in _CONTROL_SEQS:
# Known bibtex control sequence
return _CONTROL_SEQS[m.group()]
# Scan for the first alphabetic character
while pos < len(data) and depths[pos]:
if data[pos].isalpha():
return data[pos]
pos += 1
elif data[pos] == '{':
# Skip brace group
while pos < len(data) and depths[pos]:
pos += 1
else:
pos += 1
评论列表
文章目录