def check_braces(self, s): """ Raise an exception if the given string has unmatched braces. >>> w = Writer() >>> w.check_braces('Cat eats carrots.') >>> w.check_braces('Cat eats {carrots}.') >>> w.check_braces('Cat eats {carrots{}}.') >>> w.check_braces('') >>> w.check_braces('end}') >>> try: ... w.check_braces('{') ... except BibTeXError, error: ... print error String has unmatched braces: { >>> w.check_braces('{test}}') >>> try: ... w.check_braces('{{test}') ... except BibTeXError, error: ... print error String has unmatched braces: {{test} """ tokens = list(scan_bibtex_string(s)) if tokens: end_brace_level = tokens[-1][1] if end_brace_level != 0: raise BibTeXError('String has unmatched braces: %s' % s)
def is_von_name(string): if string[0].isupper(): return False if string[0].islower(): return True else: for char, brace_level in scan_bibtex_string(string): if brace_level == 0 and char.isalpha(): return char.islower() elif brace_level == 1 and char.startswith('\\'): return special_char_islower(char) return False
def check_braces(self, s): end_brace_level = list(scan_bibtex_string(s))[-1][1] if end_brace_level != 0: raise BibTeXError('String has unmatched braces: %s' % s)