comparison mercurial/match.py @ 31421:5c9cda37d7f6

match: slice over bytes to get the byteschr instead of ascii value
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 16 Mar 2017 08:03:51 +0530
parents 40704098853f
children 7aac35ada1cb
comparison
equal deleted inserted replaced
31420:40704098853f 31421:5c9cda37d7f6
491 i, n = 0, len(pat) 491 i, n = 0, len(pat)
492 res = '' 492 res = ''
493 group = 0 493 group = 0
494 escape = util.re.escape 494 escape = util.re.escape
495 def peek(): 495 def peek():
496 return i < n and pat[i] 496 return i < n and pat[i:i + 1]
497 while i < n: 497 while i < n:
498 c = pat[i] 498 c = pat[i:i + 1]
499 i += 1 499 i += 1
500 if c not in '*?[{},\\': 500 if c not in '*?[{},\\':
501 res += escape(c) 501 res += escape(c)
502 elif c == '*': 502 elif c == '*':
503 if peek() == '*': 503 if peek() == '*':
511 res += '[^/]*' 511 res += '[^/]*'
512 elif c == '?': 512 elif c == '?':
513 res += '.' 513 res += '.'
514 elif c == '[': 514 elif c == '[':
515 j = i 515 j = i
516 if j < n and pat[j] in '!]': 516 if j < n and pat[j:j + 1] in '!]':
517 j += 1 517 j += 1
518 while j < n and pat[j] != ']': 518 while j < n and pat[j:j + 1] != ']':
519 j += 1 519 j += 1
520 if j >= n: 520 if j >= n:
521 res += '\\[' 521 res += '\\['
522 else: 522 else:
523 stuff = pat[i:j].replace('\\','\\\\') 523 stuff = pat[i:j].replace('\\','\\\\')
524 i = j + 1 524 i = j + 1
525 if stuff[0] == '!': 525 if stuff[0:1] == '!':
526 stuff = '^' + stuff[1:] 526 stuff = '^' + stuff[1:]
527 elif stuff[0] == '^': 527 elif stuff[0:1] == '^':
528 stuff = '\\' + stuff 528 stuff = '\\' + stuff
529 res = '%s[%s]' % (res, stuff) 529 res = '%s[%s]' % (res, stuff)
530 elif c == '{': 530 elif c == '{':
531 group += 1 531 group += 1
532 res += '(?:' 532 res += '(?:'