[clang-format] Move irrelevant code from getRangeLength to getRemainingLength. NFC.
GitOrigin-RevId: f4d5195d2fff06e2e3daad136f909143324d0485
diff --git a/lib/Format/BreakableToken.cpp b/lib/Format/BreakableToken.cpp
index a91860f..085713b 100644
--- a/lib/Format/BreakableToken.cpp
+++ b/lib/Format/BreakableToken.cpp
@@ -539,29 +539,26 @@
unsigned Offset,
StringRef::size_type Length,
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.
- 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()) {
- LineLength -= Decoration.size();
- }
- }
- return LineLength;
+ return encoding::columnWidthWithTabs(
+ Content[LineIndex].substr(Offset, Length), StartColumn, Style.TabWidth,
+ Encoding);
}
unsigned BreakableBlockComment::getRemainingLength(unsigned LineIndex,
unsigned Offset,
unsigned StartColumn) const {
- return UnbreakableTailLength +
- getRangeLength(LineIndex, Offset, StringRef::npos, StartColumn);
+ unsigned LineLength =
+ 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.
+ bool HasRemainingText = Offset < Content[LineIndex].size();
+ if (!HasRemainingText) {
+ LineLength -= Decoration.size();
+ }
+ }
+ return LineLength;
}
unsigned BreakableBlockComment::getContentStartColumn(unsigned LineIndex,
diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp
index 7b7bccd..d84533e 100644
--- a/unittests/Format/FormatTestJS.cpp
+++ b/unittests/Format/FormatTestJS.cpp
@@ -195,7 +195,7 @@
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"