[PATCH] Clang-format: added -fromline and -toline options to specify ranges in line numbers instead of byte offsets.

Daniel Jasper djasper at google.com
Thu Jul 18 02:05:28 PDT 2013



================
Comment at: tools/clang-format/ClangFormat.cpp:58
@@ +57,3 @@
+LineRanges("lines", cl::desc("<start line>:<end line> - format a range of\n"
+                             "lines (both 1-based).\n"
+                             "Multiple ranges can be formatted by specifying\n"
----------------
Might be worth making explicit that <end line> is included. E.g.:

"(both 1-based and included)"

================
Comment at: tools/clang-format/ClangFormat.cpp:188
@@ +187,3 @@
+// Returns true on error.
+static bool convertLinesToOffsets(StringRef FileContents) {
+  if (LineRanges.empty())
----------------
I'd strongly vote against converting to offset and length first (and especially with our own implementation).

Use SourceManager::translateLineCol to get the corresponding SourceLocations in the FileID (which you have after line 236) and convert them to CharSourceRanges directly.


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



More information about the cfe-commits mailing list