blob: ace3baa660be2bdf2d925be8334ae73ad6560699 [file] [log] [blame]
Alexander Kornienko70ce7882013-04-15 14:28:00 +00001//===--- BreakableToken.cpp - Format C++ code -----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief Contains implementation of BreakableToken class and classes derived
12/// from it.
13///
14//===----------------------------------------------------------------------===//
15
Manuel Klimekde008c02013-05-27 15:23:34 +000016#define DEBUG_TYPE "format-token-breaker"
17
Alexander Kornienko70ce7882013-04-15 14:28:00 +000018#include "BreakableToken.h"
Alexander Kornienko2b2faa52013-06-11 16:01:49 +000019#include "clang/Basic/CharInfo.h"
Manuel Klimekde008c02013-05-27 15:23:34 +000020#include "clang/Format/Format.h"
Alexander Kornienko919398b2013-04-17 17:34:05 +000021#include "llvm/ADT/STLExtras.h"
Manuel Klimekde008c02013-05-27 15:23:34 +000022#include "llvm/Support/Debug.h"
Alexander Kornienko70ce7882013-04-15 14:28:00 +000023#include <algorithm>
24
25namespace clang {
26namespace format {
27
Craig Toppercf1e2162013-06-30 22:44:02 +000028static const char *const Blanks = " \t\v\f";
Alexander Kornienko8afa39b2013-06-20 13:58:37 +000029static bool IsBlank(char C) {
30 switch (C) {
31 case ' ':
32 case '\t':
33 case '\v':
34 case '\f':
35 return true;
36 default:
37 return false;
38 }
39}
40
Craig Topperb8f71642013-07-01 03:38:29 +000041static BreakableToken::Split getCommentSplit(StringRef Text,
42 unsigned ContentStartColumn,
43 unsigned ColumnLimit,
44 encoding::Encoding Encoding) {
Alexander Kornienko919398b2013-04-17 17:34:05 +000045 if (ColumnLimit <= ContentStartColumn + 1)
Manuel Klimekde008c02013-05-27 15:23:34 +000046 return BreakableToken::Split(StringRef::npos, 0);
Alexander Kornienko919398b2013-04-17 17:34:05 +000047
48 unsigned MaxSplit = ColumnLimit - ContentStartColumn + 1;
Alexander Kornienko00895102013-06-05 14:09:10 +000049 unsigned MaxSplitBytes = 0;
50
51 for (unsigned NumChars = 0;
52 NumChars < MaxSplit && MaxSplitBytes < Text.size(); ++NumChars)
53 MaxSplitBytes +=
54 encoding::getCodePointNumBytes(Text[MaxSplitBytes], Encoding);
55
Alexander Kornienko8afa39b2013-06-20 13:58:37 +000056 StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes);
Alexander Kornienko919398b2013-04-17 17:34:05 +000057 if (SpaceOffset == StringRef::npos ||
Manuel Klimekde008c02013-05-27 15:23:34 +000058 // Don't break at leading whitespace.
Alexander Kornienko8afa39b2013-06-20 13:58:37 +000059 Text.find_last_not_of(Blanks, SpaceOffset) == StringRef::npos) {
Manuel Klimekbe9ed772013-05-29 22:06:18 +000060 // Make sure that we don't break at leading whitespace that
61 // reaches past MaxSplit.
Alexander Kornienko8afa39b2013-06-20 13:58:37 +000062 StringRef::size_type FirstNonWhitespace = Text.find_first_not_of(Blanks);
Manuel Klimekbe9ed772013-05-29 22:06:18 +000063 if (FirstNonWhitespace == StringRef::npos)
64 // If the comment is only whitespace, we cannot split.
65 return BreakableToken::Split(StringRef::npos, 0);
Alexander Kornienko8afa39b2013-06-20 13:58:37 +000066 SpaceOffset = Text.find_first_of(
67 Blanks, std::max<unsigned>(MaxSplitBytes, FirstNonWhitespace));
Manuel Klimekbe9ed772013-05-29 22:06:18 +000068 }
Alexander Kornienko919398b2013-04-17 17:34:05 +000069 if (SpaceOffset != StringRef::npos && SpaceOffset != 0) {
Alexander Kornienko8afa39b2013-06-20 13:58:37 +000070 StringRef BeforeCut = Text.substr(0, SpaceOffset).rtrim(Blanks);
71 StringRef AfterCut = Text.substr(SpaceOffset).ltrim(Blanks);
Alexander Kornienko919398b2013-04-17 17:34:05 +000072 return BreakableToken::Split(BeforeCut.size(),
73 AfterCut.begin() - BeforeCut.end());
74 }
75 return BreakableToken::Split(StringRef::npos, 0);
76}
77
Craig Topperb8f71642013-07-01 03:38:29 +000078static BreakableToken::Split getStringSplit(StringRef Text,
79 unsigned ContentStartColumn,
80 unsigned ColumnLimit,
81 encoding::Encoding Encoding) {
Manuel Klimekde008c02013-05-27 15:23:34 +000082 // FIXME: Reduce unit test case.
83 if (Text.empty())
84 return BreakableToken::Split(StringRef::npos, 0);
Alexander Kornienko00895102013-06-05 14:09:10 +000085 if (ColumnLimit <= ContentStartColumn)
Manuel Klimekde008c02013-05-27 15:23:34 +000086 return BreakableToken::Split(StringRef::npos, 0);
Alexander Kornienko00895102013-06-05 14:09:10 +000087 unsigned MaxSplit =
88 std::min<unsigned>(ColumnLimit - ContentStartColumn,
89 encoding::getCodePointCount(Text, Encoding) - 1);
90 StringRef::size_type SpaceOffset = 0;
91 StringRef::size_type SlashOffset = 0;
Alexander Kornienkof2b2c7d2013-06-19 14:22:47 +000092 StringRef::size_type WordStartOffset = 0;
Alexander Kornienko00895102013-06-05 14:09:10 +000093 StringRef::size_type SplitPoint = 0;
94 for (unsigned Chars = 0;;) {
95 unsigned Advance;
96 if (Text[0] == '\\') {
97 Advance = encoding::getEscapeSequenceLength(Text);
98 Chars += Advance;
99 } else {
100 Advance = encoding::getCodePointNumBytes(Text[0], Encoding);
101 Chars += 1;
102 }
103
104 if (Chars > MaxSplit)
105 break;
106
Alexander Kornienko8afa39b2013-06-20 13:58:37 +0000107 if (IsBlank(Text[0]))
Alexander Kornienko00895102013-06-05 14:09:10 +0000108 SpaceOffset = SplitPoint;
109 if (Text[0] == '/')
110 SlashOffset = SplitPoint;
Alexander Kornienko8afa39b2013-06-20 13:58:37 +0000111 if (Advance == 1 && !isAlphanumeric(Text[0]))
Alexander Kornienkof2b2c7d2013-06-19 14:22:47 +0000112 WordStartOffset = SplitPoint;
Alexander Kornienko00895102013-06-05 14:09:10 +0000113
114 SplitPoint += Advance;
115 Text = Text.substr(Advance);
116 }
117
118 if (SpaceOffset != 0)
119 return BreakableToken::Split(SpaceOffset + 1, 0);
120 if (SlashOffset != 0)
121 return BreakableToken::Split(SlashOffset + 1, 0);
Alexander Kornienkof2b2c7d2013-06-19 14:22:47 +0000122 if (WordStartOffset != 0)
123 return BreakableToken::Split(WordStartOffset + 1, 0);
Alexander Kornienko00895102013-06-05 14:09:10 +0000124 if (SplitPoint != 0)
125 return BreakableToken::Split(SplitPoint, 0);
126 return BreakableToken::Split(StringRef::npos, 0);
Alexander Kornienko919398b2013-04-17 17:34:05 +0000127}
128
Manuel Klimekde008c02013-05-27 15:23:34 +0000129unsigned BreakableSingleLineToken::getLineCount() const { return 1; }
Alexander Kornienko70ce7882013-04-15 14:28:00 +0000130
Alexander Kornienko2785b9a2013-06-07 16:02:52 +0000131unsigned BreakableSingleLineToken::getLineLengthAfterSplit(
132 unsigned LineIndex, unsigned Offset, StringRef::size_type Length) const {
Alexander Kornienko00895102013-06-05 14:09:10 +0000133 return StartColumn + Prefix.size() + Postfix.size() +
Alexander Kornienko2785b9a2013-06-07 16:02:52 +0000134 encoding::getCodePointCount(Line.substr(Offset, Length), Encoding);
Alexander Kornienko70ce7882013-04-15 14:28:00 +0000135}
136
Alexander Kornienko16a0ec62013-06-14 11:46:10 +0000137BreakableSingleLineToken::BreakableSingleLineToken(
138 const FormatToken &Tok, unsigned StartColumn, StringRef Prefix,
139 StringRef Postfix, bool InPPDirective, encoding::Encoding Encoding)
140 : BreakableToken(Tok, InPPDirective, Encoding), StartColumn(StartColumn),
141 Prefix(Prefix), Postfix(Postfix) {
Manuel Klimekde008c02013-05-27 15:23:34 +0000142 assert(Tok.TokenText.startswith(Prefix) && Tok.TokenText.endswith(Postfix));
143 Line = Tok.TokenText.substr(
144 Prefix.size(), Tok.TokenText.size() - Prefix.size() - Postfix.size());
Alexander Kornienko70ce7882013-04-15 14:28:00 +0000145}
146
Manuel Klimekde008c02013-05-27 15:23:34 +0000147BreakableStringLiteral::BreakableStringLiteral(const FormatToken &Tok,
Alexander Kornienko00895102013-06-05 14:09:10 +0000148 unsigned StartColumn,
Alexander Kornienko16a0ec62013-06-14 11:46:10 +0000149 bool InPPDirective,
Alexander Kornienko00895102013-06-05 14:09:10 +0000150 encoding::Encoding Encoding)
Alexander Kornienko16a0ec62013-06-14 11:46:10 +0000151 : BreakableSingleLineToken(Tok, StartColumn, "\"", "\"", InPPDirective,
152 Encoding) {}
Manuel Klimekde008c02013-05-27 15:23:34 +0000153
154BreakableToken::Split
155BreakableStringLiteral::getSplit(unsigned LineIndex, unsigned TailOffset,
156 unsigned ColumnLimit) const {
Alexander Kornienko00895102013-06-05 14:09:10 +0000157 return getStringSplit(Line.substr(TailOffset), StartColumn + 2, ColumnLimit,
158 Encoding);
Alexander Kornienko919398b2013-04-17 17:34:05 +0000159}
160
Alexander Kornienko2b2faa52013-06-11 16:01:49 +0000161void BreakableStringLiteral::insertBreak(unsigned LineIndex,
162 unsigned TailOffset, Split Split,
Alexander Kornienko2b2faa52013-06-11 16:01:49 +0000163 WhitespaceManager &Whitespaces) {
164 Whitespaces.replaceWhitespaceInToken(
165 Tok, Prefix.size() + TailOffset + Split.first, Split.second, Postfix,
166 Prefix, InPPDirective, 1, StartColumn);
167}
168
Manuel Klimekde008c02013-05-27 15:23:34 +0000169static StringRef getLineCommentPrefix(StringRef Comment) {
Alexander Kornienko919398b2013-04-17 17:34:05 +0000170 const char *KnownPrefixes[] = { "/// ", "///", "// ", "//" };
Manuel Klimekde008c02013-05-27 15:23:34 +0000171 for (size_t i = 0, e = llvm::array_lengthof(KnownPrefixes); i != e; ++i)
Alexander Kornienko919398b2013-04-17 17:34:05 +0000172 if (Comment.startswith(KnownPrefixes[i]))
173 return KnownPrefixes[i];
174 return "";
175}
176
Manuel Klimekde008c02013-05-27 15:23:34 +0000177BreakableLineComment::BreakableLineComment(const FormatToken &Token,
Alexander Kornienko00895102013-06-05 14:09:10 +0000178 unsigned StartColumn,
Alexander Kornienko16a0ec62013-06-14 11:46:10 +0000179 bool InPPDirective,
Alexander Kornienko00895102013-06-05 14:09:10 +0000180 encoding::Encoding Encoding)
Manuel Klimekde008c02013-05-27 15:23:34 +0000181 : BreakableSingleLineToken(Token, StartColumn,
Alexander Kornienko00895102013-06-05 14:09:10 +0000182 getLineCommentPrefix(Token.TokenText), "",
Alexander Kornienko16a0ec62013-06-14 11:46:10 +0000183 InPPDirective, Encoding) {
Alexander Kornienko2b2faa52013-06-11 16:01:49 +0000184 OriginalPrefix = Prefix;
185 if (Token.TokenText.size() > Prefix.size() &&
186 isAlphanumeric(Token.TokenText[Prefix.size()])) {
187 if (Prefix == "//")
188 Prefix = "// ";
189 else if (Prefix == "///")
190 Prefix = "/// ";
191 }
192}
Manuel Klimekde008c02013-05-27 15:23:34 +0000193
194BreakableToken::Split
195BreakableLineComment::getSplit(unsigned LineIndex, unsigned TailOffset,
196 unsigned ColumnLimit) const {
197 return getCommentSplit(Line.substr(TailOffset), StartColumn + Prefix.size(),
Alexander Kornienko00895102013-06-05 14:09:10 +0000198 ColumnLimit, Encoding);
Manuel Klimekde008c02013-05-27 15:23:34 +0000199}
200
Alexander Kornienko2b2faa52013-06-11 16:01:49 +0000201void BreakableLineComment::insertBreak(unsigned LineIndex, unsigned TailOffset,
Alexander Kornienko16a0ec62013-06-14 11:46:10 +0000202 Split Split,
Alexander Kornienko2b2faa52013-06-11 16:01:49 +0000203 WhitespaceManager &Whitespaces) {
204 Whitespaces.replaceWhitespaceInToken(
205 Tok, OriginalPrefix.size() + TailOffset + Split.first, Split.second,
206 Postfix, Prefix, InPPDirective, 1, StartColumn);
207}
208
209void
210BreakableLineComment::replaceWhitespaceBefore(unsigned LineIndex,
Alexander Kornienko2b2faa52013-06-11 16:01:49 +0000211 WhitespaceManager &Whitespaces) {
212 if (OriginalPrefix != Prefix) {
213 Whitespaces.replaceWhitespaceInToken(Tok, OriginalPrefix.size(), 0, "", "",
214 false, 0, 1);
215 }
216}
217
Alexander Kornienko00895102013-06-05 14:09:10 +0000218BreakableBlockComment::BreakableBlockComment(
219 const FormatStyle &Style, const FormatToken &Token, unsigned StartColumn,
Alexander Kornienko16a0ec62013-06-14 11:46:10 +0000220 unsigned OriginalStartColumn, bool FirstInLine, bool InPPDirective,
221 encoding::Encoding Encoding)
222 : BreakableToken(Token, InPPDirective, Encoding) {
Manuel Klimekde008c02013-05-27 15:23:34 +0000223 StringRef TokenText(Token.TokenText);
224 assert(TokenText.startswith("/*") && TokenText.endswith("*/"));
225 TokenText.substr(2, TokenText.size() - 4).split(Lines, "\n");
226
227 int IndentDelta = StartColumn - OriginalStartColumn;
228 bool NeedsStar = true;
229 LeadingWhitespace.resize(Lines.size());
230 StartOfLineColumn.resize(Lines.size());
231 if (Lines.size() == 1 && !FirstInLine) {
232 // Comments for which FirstInLine is false can start on arbitrary column,
233 // and available horizontal space can be too small to align consecutive
234 // lines with the first one.
235 // FIXME: We could, probably, align them to current indentation level, but
236 // now we just wrap them without stars.
237 NeedsStar = false;
238 }
239 StartOfLineColumn[0] = StartColumn + 2;
240 for (size_t i = 1; i < Lines.size(); ++i) {
241 adjustWhitespace(Style, i, IndentDelta);
242 if (Lines[i].empty())
243 // If the last line is empty, the closing "*/" will have a star.
244 NeedsStar = NeedsStar && i + 1 == Lines.size();
245 else
246 NeedsStar = NeedsStar && Lines[i][0] == '*';
247 }
248 Decoration = NeedsStar ? "* " : "";
249 IndentAtLineBreak = StartOfLineColumn[0] + 1;
250 for (size_t i = 1; i < Lines.size(); ++i) {
251 if (Lines[i].empty()) {
252 if (!NeedsStar && i + 1 != Lines.size())
253 // For all but the last line (which always ends in */), set the
254 // start column to 0 if they're empty, so we do not insert
255 // trailing whitespace anywhere.
256 StartOfLineColumn[i] = 0;
257 continue;
258 }
259 if (NeedsStar) {
260 // The first line already excludes the star.
261 // For all other lines, adjust the line to exclude the star and
262 // (optionally) the first whitespace.
263 int Offset = Lines[i].startswith("* ") ? 2 : 1;
264 StartOfLineColumn[i] += Offset;
265 Lines[i] = Lines[i].substr(Offset);
266 LeadingWhitespace[i] += Offset;
267 }
268 IndentAtLineBreak = std::min<int>(IndentAtLineBreak, StartOfLineColumn[i]);
269 }
Daniel Jaspercb4b40b2013-05-30 17:27:48 +0000270 IndentAtLineBreak = std::max<unsigned>(IndentAtLineBreak, Decoration.size());
Manuel Klimekde008c02013-05-27 15:23:34 +0000271 DEBUG({
272 for (size_t i = 0; i < Lines.size(); ++i) {
273 llvm::dbgs() << i << " |" << Lines[i] << "| " << LeadingWhitespace[i]
274 << "\n";
275 }
276 });
277}
278
279void BreakableBlockComment::adjustWhitespace(const FormatStyle &Style,
280 unsigned LineIndex,
281 int IndentDelta) {
Alexander Kornienko16a0ec62013-06-14 11:46:10 +0000282 // When in a preprocessor directive, the trailing backslash in a block comment
283 // is not needed, but can serve a purpose of uniformity with necessary escaped
284 // newlines outside the comment. In this case we remove it here before
285 // trimming the trailing whitespace. The backslash will be re-added later when
286 // inserting a line break.
287 size_t EndOfPreviousLine = Lines[LineIndex - 1].size();
288 if (InPPDirective && Lines[LineIndex - 1].endswith("\\"))
289 --EndOfPreviousLine;
290
Manuel Klimekde008c02013-05-27 15:23:34 +0000291 // Calculate the end of the non-whitespace text in the previous line.
Alexander Kornienko16a0ec62013-06-14 11:46:10 +0000292 EndOfPreviousLine =
Alexander Kornienko8afa39b2013-06-20 13:58:37 +0000293 Lines[LineIndex - 1].find_last_not_of(Blanks, EndOfPreviousLine);
Manuel Klimekde008c02013-05-27 15:23:34 +0000294 if (EndOfPreviousLine == StringRef::npos)
295 EndOfPreviousLine = 0;
296 else
297 ++EndOfPreviousLine;
298 // Calculate the start of the non-whitespace text in the current line.
Alexander Kornienko8afa39b2013-06-20 13:58:37 +0000299 size_t StartOfLine = Lines[LineIndex].find_first_not_of(Blanks);
Manuel Klimekde008c02013-05-27 15:23:34 +0000300 if (StartOfLine == StringRef::npos)
301 StartOfLine = Lines[LineIndex].size();
Manuel Klimekde008c02013-05-27 15:23:34 +0000302
303 // Adjust Lines to only contain relevant text.
304 Lines[LineIndex - 1] = Lines[LineIndex - 1].substr(0, EndOfPreviousLine);
305 Lines[LineIndex] = Lines[LineIndex].substr(StartOfLine);
306 // Adjust LeadingWhitespace to account all whitespace between the lines
307 // to the current line.
308 LeadingWhitespace[LineIndex] =
309 Lines[LineIndex].begin() - Lines[LineIndex - 1].end();
Manuel Klimekd63312b2013-05-28 10:01:59 +0000310
311 // FIXME: We currently count tabs as 1 character. To solve this, we need to
312 // get the correct indentation width of the start of the comment, which
313 // requires correct counting of the tab expansions before the comment, and
314 // a configurable tab width. Since the current implementation only breaks
315 // if leading tabs are intermixed with spaces, that is not a high priority.
316
Manuel Klimekde008c02013-05-27 15:23:34 +0000317 // Adjust the start column uniformly accross all lines.
Manuel Klimekd63312b2013-05-28 10:01:59 +0000318 StartOfLineColumn[LineIndex] = std::max<int>(0, StartOfLine + IndentDelta);
Manuel Klimekde008c02013-05-27 15:23:34 +0000319}
320
321unsigned BreakableBlockComment::getLineCount() const { return Lines.size(); }
322
Alexander Kornienko2785b9a2013-06-07 16:02:52 +0000323unsigned BreakableBlockComment::getLineLengthAfterSplit(
324 unsigned LineIndex, unsigned Offset, StringRef::size_type Length) const {
325 return getContentStartColumn(LineIndex, Offset) +
326 encoding::getCodePointCount(Lines[LineIndex].substr(Offset, Length),
Alexander Kornienko00895102013-06-05 14:09:10 +0000327 Encoding) +
Manuel Klimekde008c02013-05-27 15:23:34 +0000328 // The last line gets a "*/" postfix.
329 (LineIndex + 1 == Lines.size() ? 2 : 0);
330}
331
332BreakableToken::Split
333BreakableBlockComment::getSplit(unsigned LineIndex, unsigned TailOffset,
334 unsigned ColumnLimit) const {
335 return getCommentSplit(Lines[LineIndex].substr(TailOffset),
336 getContentStartColumn(LineIndex, TailOffset),
Alexander Kornienko00895102013-06-05 14:09:10 +0000337 ColumnLimit, Encoding);
Manuel Klimekde008c02013-05-27 15:23:34 +0000338}
339
340void BreakableBlockComment::insertBreak(unsigned LineIndex, unsigned TailOffset,
Alexander Kornienko16a0ec62013-06-14 11:46:10 +0000341 Split Split,
Manuel Klimekde008c02013-05-27 15:23:34 +0000342 WhitespaceManager &Whitespaces) {
343 StringRef Text = Lines[LineIndex].substr(TailOffset);
344 StringRef Prefix = Decoration;
345 if (LineIndex + 1 == Lines.size() &&
346 Text.size() == Split.first + Split.second) {
347 // For the last line we need to break before "*/", but not to add "* ".
348 Prefix = "";
349 }
350
351 unsigned BreakOffsetInToken =
352 Text.data() - Tok.TokenText.data() + Split.first;
353 unsigned CharsToRemove = Split.second;
Manuel Klimekb6dba332013-05-30 07:45:53 +0000354 assert(IndentAtLineBreak >= Decoration.size());
Alexander Kornienko2b2faa52013-06-11 16:01:49 +0000355 Whitespaces.replaceWhitespaceInToken(Tok, BreakOffsetInToken, CharsToRemove,
356 "", Prefix, InPPDirective, 1,
357 IndentAtLineBreak - Decoration.size());
Manuel Klimekde008c02013-05-27 15:23:34 +0000358}
359
360void
361BreakableBlockComment::replaceWhitespaceBefore(unsigned LineIndex,
Manuel Klimekde008c02013-05-27 15:23:34 +0000362 WhitespaceManager &Whitespaces) {
363 if (LineIndex == 0)
364 return;
365 StringRef Prefix = Decoration;
Manuel Klimekc5cc4bf2013-05-28 08:55:01 +0000366 if (Lines[LineIndex].empty()) {
367 if (LineIndex + 1 == Lines.size()) {
368 // If the last line is empty, we don't need a prefix, as the */ will line
369 // up with the decoration (if it exists).
370 Prefix = "";
371 } else if (!Decoration.empty()) {
372 // For other empty lines, if we do have a decoration, adapt it to not
373 // contain a trailing whitespace.
374 Prefix = Prefix.substr(0, 1);
375 }
Daniel Jaspere2c482f2013-05-30 06:40:07 +0000376 } else {
377 if (StartOfLineColumn[LineIndex] == 1) {
378 // This lines starts immediately after the decorating *.
379 Prefix = Prefix.substr(0, 1);
380 }
Manuel Klimekc5cc4bf2013-05-28 08:55:01 +0000381 }
Manuel Klimekde008c02013-05-27 15:23:34 +0000382
383 unsigned WhitespaceOffsetInToken =
384 Lines[LineIndex].data() - Tok.TokenText.data() -
385 LeadingWhitespace[LineIndex];
Manuel Klimekb6dba332013-05-30 07:45:53 +0000386 assert(StartOfLineColumn[LineIndex] >= Prefix.size());
Alexander Kornienko2b2faa52013-06-11 16:01:49 +0000387 Whitespaces.replaceWhitespaceInToken(
Manuel Klimekde008c02013-05-27 15:23:34 +0000388 Tok, WhitespaceOffsetInToken, LeadingWhitespace[LineIndex], "", Prefix,
Alexander Kornienko2b2faa52013-06-11 16:01:49 +0000389 InPPDirective, 1, StartOfLineColumn[LineIndex] - Prefix.size());
Manuel Klimekde008c02013-05-27 15:23:34 +0000390}
391
392unsigned
393BreakableBlockComment::getContentStartColumn(unsigned LineIndex,
394 unsigned TailOffset) const {
395 // If we break, we always break at the predefined indent.
396 if (TailOffset != 0)
397 return IndentAtLineBreak;
398 return StartOfLineColumn[LineIndex];
399}
400
Alexander Kornienko70ce7882013-04-15 14:28:00 +0000401} // namespace format
402} // namespace clang