##// END OF EJS Templates
util: add flag support to compilere
Bryan O'Sullivan -
r18775:5b05ceb2 default
parent child Browse files
Show More
@@ -662,10 +662,12 b' try:'
662 662 except ImportError:
663 663 _re2 = False
664 664
665 def compilere(pat):
665 def compilere(pat, flags=0):
666 666 '''Compile a regular expression, using re2 if possible
667 667
668 For best performance, use only re2-compatible regexp features.'''
668 For best performance, use only re2-compatible regexp features. The
669 only flags from the re module that are re2-compatible are
670 IGNORECASE and MULTILINE.'''
669 671 global _re2
670 672 if _re2 is None:
671 673 try:
@@ -673,12 +675,16 b' def compilere(pat):'
673 675 _re2 = True
674 676 except ImportError:
675 677 _re2 = False
676 if _re2:
678 if _re2 and (flags & ~(re.IGNORECASE | re.MULTILINE)) == 0:
679 if flags & re.IGNORECASE:
680 pat = '(?i)' + pat
681 if flags & re.MULTILINE:
682 pat = '(?m)' + pat
677 683 try:
678 684 return re2.compile(pat)
679 685 except re2.error:
680 686 pass
681 return re.compile(pat)
687 return re.compile(pat, flags)
682 688
683 689 _fspathcache = {}
684 690 def fspath(name, root):
General Comments 0
You need to be logged in to leave comments. Login now