Пример #1
0
 def match_link_dest(cls, string, offset):
     offset = shift_whitespace(string, offset + 1)
     if offset == len(string):
         return None
     if string[offset] == '<':
         escaped = False
         for i, c in enumerate(string[offset + 1:], start=offset + 1):
             if c == '\\' and not escaped:
                 escaped = True
             elif c == ' ' or c == '\n' or (c == '<' and not escaped):
                 return None
             elif c == '>' and not escaped:
                 return offset, i + 1, string[offset + 1:i]
             elif escaped:
                 escaped = False
         return None
     else:
         escaped = False
         count = 0
         for i, c in enumerate(string[offset:], start=offset):
             if c == '\\' and not escaped:
                 escaped = True
             elif c in whitespace:
                 break
             elif not escaped:
                 if c == '(':
                     count += 1
                 elif c == ')':
                     count -= 1
             elif is_control_char(c):
                 return None
             elif escaped:
                 escaped = False
         if count != 0:
             return None
         return offset, i, string[offset:i]
Пример #2
0
 def test_is_control_char(self):
     char = chr(0)
     self.assertTrue(is_control_char(char))
     self.assertFalse(is_control_char('a'))