mercurial/match.py
changeset 40684 e6c9ef5e11a0
parent 40345 d30a19d10441
child 40685 e41f6c2e69c4
equal deleted inserted replaced
40683:d7936a9dad47 40684:e6c9ef5e11a0
  1055     \.\*\?
  1055     \.\*\?
  1056     '''
  1056     '''
  1057     i, n = 0, len(pat)
  1057     i, n = 0, len(pat)
  1058     res = ''
  1058     res = ''
  1059     group = 0
  1059     group = 0
  1060     escape = util.stringutil.reescape
  1060     escape = util.stringutil.regexbytesescapemap.get
  1061     def peek():
  1061     def peek():
  1062         return i < n and pat[i:i + 1]
  1062         return i < n and pat[i:i + 1]
  1063     while i < n:
  1063     while i < n:
  1064         c = pat[i:i + 1]
  1064         c = pat[i:i + 1]
  1065         i += 1
  1065         i += 1
  1066         if c not in '*?[{},\\':
  1066         if c not in '*?[{},\\':
  1067             res += escape(c)
  1067             res += escape(c, c)
  1068         elif c == '*':
  1068         elif c == '*':
  1069             if peek() == '*':
  1069             if peek() == '*':
  1070                 i += 1
  1070                 i += 1
  1071                 if peek() == '/':
  1071                 if peek() == '/':
  1072                     i += 1
  1072                     i += 1
  1103             res += '|'
  1103             res += '|'
  1104         elif c == '\\':
  1104         elif c == '\\':
  1105             p = peek()
  1105             p = peek()
  1106             if p:
  1106             if p:
  1107                 i += 1
  1107                 i += 1
  1108                 res += escape(p)
  1108                 res += escape(p, p)
  1109             else:
  1109             else:
  1110                 res += escape(c)
  1110                 res += escape(c, c)
  1111         else:
  1111         else:
  1112             res += escape(c)
  1112             res += escape(c, c)
  1113     return res
  1113     return res
  1114 
  1114 
  1115 def _regex(kind, pat, globsuffix):
  1115 def _regex(kind, pat, globsuffix):
  1116     '''Convert a (normalized) pattern of any kind into a regular expression.
  1116     '''Convert a (normalized) pattern of any kind into a regular expression.
  1117     globsuffix is appended to the regexp of globs.'''
  1117     globsuffix is appended to the regexp of globs.'''