[PATCH] Added -iregex for case-insensitive regex to filter file names.

Alexander Kornienko alexfh at google.com
Mon Dec 16 02:43:16 PST 2013


Hi djasper,

-regex and -iregex both mimic options of the find utility.
Made the default list of extensions case-insensitive, so that it's not only C
and CPP extensions are accepted in upper case.

http://llvm-reviews.chandlerc.com/D2415

Files:
  tools/clang-format/clang-format-diff.py

Index: tools/clang-format/clang-format-diff.py
===================================================================
--- tools/clang-format/clang-format-diff.py
+++ tools/clang-format/clang-format-diff.py
@@ -43,9 +43,13 @@
                       help='apply edits to files instead of displaying a diff')
   parser.add_argument('-p', metavar='NUM', default=0,
                       help='strip the smallest prefix containing P slashes')
-  parser.add_argument('-regex', metavar='PATTERN', default=
-                      r'.*\.(cpp|cc|CPP|C|c\+\+|cxx|c|h|hpp|m|mm|inc|js)',
-                      help='custom pattern selecting file paths to reformat')
+  parser.add_argument('-regex', metavar='PATTERN', default='',
+                      help='custom pattern selecting file paths to reformat '
+                      '(case sensitive, can\'t be used with -iregex)')
+  parser.add_argument('-iregex', metavar='PATTERN', default=
+                      r'.*\.(cpp|cc|c\+\+|cxx|c|h|hpp|m|mm|inc|js)',
+                      help='custom pattern selecting file paths to reformat '
+                      '(case insensitive, can\'t be used with -regex)')
   parser.add_argument(
       '-style',
       help=
@@ -62,8 +66,12 @@
     if filename == None:
       continue
 
-    if not re.match(args.regex, filename):
-      continue
+    if args.regex != '':
+      if not re.match(args.regex, filename):
+        continue
+    else:
+      if not re.match(args.iregex, filename, re.IGNORECASE):
+        continue
 
     match = re.search('^@@.*\+(\d+)(,(\d+))?', line)
     if match:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2415.1.patch
Type: text/x-patch
Size: 1580 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131216/c96543d9/attachment.bin>


More information about the cfe-commits mailing list