示例#1
0
    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)
示例#2
0
    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)
示例#3
0
 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
示例#4
0
 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
示例#5
0
文件: bibtex.py 项目: rybesh/pybtex
 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)