Author: Marek Kurdej Date: 2022-01-28T12:01:02+01:00 New Revision: f4d5195d2fff06e2e3daad136f909143324d0485
URL: https://github.com/llvm/llvm-project/commit/f4d5195d2fff06e2e3daad136f909143324d0485 DIFF: https://github.com/llvm/llvm-project/commit/f4d5195d2fff06e2e3daad136f909143324d0485.diff LOG: [clang-format] Move irrelevant code from getRangeLength to getRemainingLength. NFC. Added: Modified: clang/lib/Format/BreakableToken.cpp clang/unittests/Format/FormatTestJS.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp index a91860faf74ec..085713b5c81ca 100644 --- a/clang/lib/Format/BreakableToken.cpp +++ b/clang/lib/Format/BreakableToken.cpp @@ -539,31 +539,28 @@ unsigned BreakableBlockComment::getRangeLength(unsigned LineIndex, unsigned Offset, StringRef::size_type Length, unsigned StartColumn) const { + return encoding::columnWidthWithTabs( + Content[LineIndex].substr(Offset, Length), StartColumn, Style.TabWidth, + Encoding); +} + +unsigned BreakableBlockComment::getRemainingLength(unsigned LineIndex, + unsigned Offset, + unsigned StartColumn) const { unsigned LineLength = - encoding::columnWidthWithTabs(Content[LineIndex].substr(Offset, Length), - StartColumn, Style.TabWidth, Encoding); - // FIXME: This should go into getRemainingLength instead, but we currently - // break tests when putting it there. Investigate how to fix those tests. - // The last line gets a "*/" postfix. + UnbreakableTailLength + + getRangeLength(LineIndex, Offset, StringRef::npos, StartColumn); if (LineIndex + 1 == Lines.size()) { LineLength += 2; // We never need a decoration when breaking just the trailing "*/" postfix. - // Note that checking that Length == 0 is not enough, since Length could - // also be StringRef::npos. - if (Content[LineIndex].substr(Offset).empty()) { + bool HasRemainingText = Offset < Content[LineIndex].size(); + if (!HasRemainingText) { LineLength -= Decoration.size(); } } return LineLength; } -unsigned BreakableBlockComment::getRemainingLength(unsigned LineIndex, - unsigned Offset, - unsigned StartColumn) const { - return UnbreakableTailLength + - getRangeLength(LineIndex, Offset, StringRef::npos, StartColumn); -} - unsigned BreakableBlockComment::getContentStartColumn(unsigned LineIndex, bool Break) const { if (Break) diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 7b7bccda0805d..d84533e8a2b03 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -195,7 +195,7 @@ TEST_F(FormatTestJS, JSDocComments) { getGoogleJSStyleWithColumns(20))); // FIXME: this overcounts the */ as a continuation of the 12 when breaking. - // Related to the FIXME in BreakableBlockComment::getRangeLength. + // Cf. BreakableBlockComment::getRemainingLength. EXPECT_EQ("/**\n" " * @returns {string}\n" " * jsdoc line line\n" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits