StringRef
Blanks=
" \t\v\f\r";
44 static constexprStringRef KnownCStylePrefixes[] = {
"///<",
"//!<",
"///",
45 "//!",
"//:",
"//"};
46 static constexprStringRef KnownTextProtoPrefixes[] = {
"####",
"###",
"##",
50KnownPrefixes = KnownTextProtoPrefixes;
53llvm::is_sorted(KnownPrefixes, [](StringRef Lhs, StringRef Rhs)
noexcept{
54 returnLhs.size() > Rhs.size();
57 for(StringRef KnownPrefix : KnownPrefixes) {
58 if(Comment.starts_with(KnownPrefix)) {
59 const autoPrefixLength =
60Comment.find_first_not_of(
' ', KnownPrefix.size());
61 returnComment.substr(0, PrefixLength);
69 unsignedColumnLimit,
unsignedTabWidth,
71 boolDecorationEndsWithStar =
false) {
72LLVM_DEBUG(llvm::dbgs() <<
"Comment split: \""<<
Text 73<<
"\", Column limit: "<< ColumnLimit
74<<
", Content start: "<< ContentStartColumn <<
"\n");
75 if(ColumnLimit <= ContentStartColumn + 1)
78 unsignedMaxSplit = ColumnLimit - ContentStartColumn + 1;
79 unsignedMaxSplitBytes = 0;
81 for(
unsignedNumChars = 0;
82NumChars < MaxSplit && MaxSplitBytes <
Text.size();) {
83 unsignedBytesInChar =
86 Text.substr(MaxSplitBytes, BytesInChar), ContentStartColumn + NumChars,
88MaxSplitBytes += BytesInChar;
95StringRef::size_type SpaceOffset =
97 if(SpaceOffset != StringRef::npos && SpaceOffset + 1 <
Text.size() &&
98 Text[SpaceOffset + 1] ==
'{') {
99MaxSplitBytes = SpaceOffset + 1;
103StringRef::size_type SpaceOffset =
Text.find_last_of(
Blanks, MaxSplitBytes);
105 static const autokNumberedListRegexp = llvm::Regex(
"^[1-9][0-9]?\\.");
107 while(SpaceOffset != StringRef::npos) {
113 if(Style.
isCpp()) {
114StringRef::size_type LastNonBlank =
115 Text.find_last_not_of(
Blanks, SpaceOffset);
116 if(LastNonBlank != StringRef::npos &&
Text[LastNonBlank] ==
'\\') {
117SpaceOffset =
Text.find_last_of(
Blanks, LastNonBlank);
124 if(kNumberedListRegexp.match(
Text.substr(SpaceOffset).ltrim(
Blanks))) {
125SpaceOffset =
Text.find_last_of(
Blanks, SpaceOffset);
131(
Text[SpaceOffset + 1] ==
'{'||
Text[SpaceOffset + 1] ==
'@')) {
132SpaceOffset =
Text.find_last_of(
Blanks, SpaceOffset);
139 if(SpaceOffset == StringRef::npos ||
141 Text.find_last_not_of(
Blanks, SpaceOffset) == StringRef::npos) {
144StringRef::size_type FirstNonWhitespace =
Text.find_first_not_of(
Blanks);
145 if(FirstNonWhitespace == StringRef::npos) {
149SpaceOffset =
Text.find_first_of(
150 Blanks, std::max<unsigned>(MaxSplitBytes, FirstNonWhitespace));
152 if(SpaceOffset != StringRef::npos && SpaceOffset != 0) {
157 if(SpaceOffset == 1 &&
Text[SpaceOffset - 1] ==
'*')
159StringRef BeforeCut =
Text.substr(0, SpaceOffset).rtrim(
Blanks);
160StringRef AfterCut =
Text.substr(SpaceOffset);
162 if(!DecorationEndsWithStar || AfterCut.size() <= 1 || AfterCut[1] !=
'/')
163AfterCut = AfterCut.ltrim(
Blanks);
165AfterCut.begin() - BeforeCut.end());
176 if(ColumnLimit <= UsedColumns)
178 unsignedMaxSplit = ColumnLimit - UsedColumns;
179StringRef::size_type SpaceOffset = 0;
180StringRef::size_type SlashOffset = 0;
181StringRef::size_type WordStartOffset = 0;
182StringRef::size_type SplitPoint = 0;
183 for(
unsignedChars = 0;;) {
185 if(
Text[0] ==
'\\') {
191 Text.substr(0, Advance), UsedColumns + Chars, TabWidth, Encoding);
194 if(Chars > MaxSplit ||
Text.size() <= Advance)
198SpaceOffset = SplitPoint;
199 if(
Text[0] ==
'/')
200SlashOffset = SplitPoint;
202WordStartOffset = SplitPoint;
204SplitPoint += Advance;
208 if(SpaceOffset != 0)
210 if(SlashOffset != 0)
212 if(WordStartOffset != 0)
220assert((
Token.
is(TT_BlockComment) ||
Token.
is(TT_LineComment)) &&
221 "formatting regions are switched by comment tokens");
222StringRef Content =
Token.TokenText.substr(2).ltrim();
223 returnContent.starts_with(
"clang-format on") ||
224Content.starts_with(
"clang-format off");
241 returnRemainingTokenColumns + 1 -
Split.second;
248StringRef::size_type Length,
249 unsignedStartColumn)
const{
250llvm_unreachable(
"Getting the length of a part of the string literal " 251 "indicates that the code tries to reflow it.");
256 unsignedStartColumn)
const{
268 const FormatToken&Tok,
unsignedStartColumn, StringRef Prefix,
269StringRef Postfix,
unsignedUnbreakableTailLength,
boolInPPDirective,
272StartColumn(StartColumn), Prefix(Prefix), Postfix(Postfix),
273UnbreakableTailLength(UnbreakableTailLength) {
280 unsignedLineIndex,
unsignedTailOffset,
unsignedColumnLimit,
281 unsignedContentStartColumn,
constllvm::Regex &CommentPragmasRegex)
const{
288 unsignedContentIndent,
290Whitespaces.replaceWhitespaceInToken(
297 unsignedStartColumn,
unsignedUnbreakableTailLength,
boolInPPDirective,
300Tok, StartColumn,
QuoteStyle == SingleQuotes ?
"'" 301: QuoteStyle == AtDoubleQuotes ?
"@\"" 303QuoteStyle == SingleQuotes ?
"'":
"\"",
304UnbreakableTailLength, InPPDirective, Encoding, Style),
305BracesNeeded(Tok.isNot(TT_StringInConcatenation)),
306QuoteStyle(QuoteStyle) {
332 Postfix= SignOnNewLine ?
"'":
"' +";
333 Prefix= SignOnNewLine ?
"+ '":
"'";
337 Prefix= SignOnNewLine ?
"+ @\"":
"@\"";
340 Prefix= SignOnNewLine ?
"+ \"":
"\"";
343 Postfix= SignOnNewLine ?
"\"":
"\" +";
358 unsignedLineIndex,
unsignedOffset,
unsignedStartColumn)
const{
377 unsignedLineIndex,
unsignedTailOffset,
Split Split,
379Whitespaces.replaceWhitespaceInToken(
399Whitespaces.replaceWhitespaceInToken(
403Whitespaces.replaceWhitespaceInToken(
410 unsignedStartColumn,
boolInPPDirective,
414StartColumn(StartColumn) {}
420 unsignedColumnLimit,
unsignedContentStartColumn,
421 constllvm::Regex &CommentPragmasRegex)
const{
424 return Split(StringRef::npos, 0);
431 unsignedLineIndex,
unsignedTailOffset,
Split Split,
433StringRef
Text=
Content[LineIndex].substr(TailOffset);
438 unsignedBreakOffsetInToken =
440 unsignedCharsToRemove =
Split.second;
441Whitespaces.replaceWhitespaceInToken(
442 tokenAt(LineIndex), BreakOffsetInToken, CharsToRemove,
"",
"",
451Content = Content.trim(
Blanks);
454 boolhasSpecialMeaningPrefix =
false;
455 for(StringRef Prefix :
456{
"@",
"\\",
"TODO",
"FIXME",
"XXX",
"-# ",
"- ",
"+ ",
"* "}) {
457 if(Content.starts_with(Prefix)) {
458hasSpecialMeaningPrefix =
true;
466 static const autokNumberedListRegexp = llvm::Regex(
"^[1-9][0-9]?\\. ");
467hasSpecialMeaningPrefix =
468hasSpecialMeaningPrefix || kNumberedListRegexp.match(Content);
473 returnContent.size() >= 2 && !hasSpecialMeaningPrefix &&
474!Content.ends_with(
"\\") &&
482 unsignedOriginalStartColumn,
boolFirstInLine,
boolInPPDirective,
485DelimitersOnNewline(
false),
486UnbreakableTailLength(
Token.UnbreakableTailLength) {
487assert(
Tok.
is(TT_BlockComment) &&
488 "block comment section must start with a block comment");
491assert(TokenText.starts_with(
"/*") && TokenText.ends_with(
"*/"));
492TokenText.substr(2, TokenText.size() - 4)
493.split(
Lines, UseCRLF ?
"\r\n":
"\n");
495 intIndentDelta =
StartColumn- OriginalStartColumn;
502 for(
size_ti = 1; i <
Lines.size(); ++i)
503adjustWhitespace(i, IndentDelta);
514 if(
Lines.size() >= 2 &&
Content[1].starts_with(
"**") &&
520 if(
Lines.size() == 1 && !FirstInLine) {
528 for(
size_ti = 1, e =
Content.size(); i < e && !Decoration.empty(); ++i) {
534}
else if(!
Text.empty() && Decoration.starts_with(
Text)) {
537 while(!
Text.starts_with(Decoration))
538Decoration = Decoration.drop_back(1);
541LastLineNeedsDecoration =
true;
543 for(
size_ti = 1, e =
Lines.size(); i < e; ++i) {
549LastLineNeedsDecoration =
false;
551 if(e >= 2 && !Decoration.empty())
553}
else if(Decoration.empty()) {
565 unsignedDecorationSize = Decoration.starts_with(
Content[i])
571 if(!Decoration.starts_with(
Content[i])) {
573std::min<int>(IndentAtLineBreak, std::max(0,
ContentColumn[i]));
576IndentAtLineBreak = std::max<unsigned>(IndentAtLineBreak, Decoration.size());
580 if((
Lines[0] ==
"*"||
Lines[0].starts_with(
"* ")) &&
Lines.size() > 1) {
582DelimitersOnNewline =
true;
583}
else if(
Lines[0].starts_with(
"* ") &&
Lines.size() == 1) {
597llvm::dbgs() <<
"IndentAtLineBreak "<< IndentAtLineBreak <<
"\n";
598llvm::dbgs() <<
"DelimitersOnNewline "<< DelimitersOnNewline <<
"\n";
599 for(
size_ti = 0; i <
Lines.size(); ++i) {
600llvm::dbgs() << i <<
" |"<<
Content[i] <<
"| " 602<<
"IN="<< (
Content[i].data() -
Lines[i].data()) <<
"\n";
608 unsignedLineIndex,
unsignedTailOffset,
unsignedColumnLimit,
609 unsignedContentStartColumn,
constllvm::Regex &CommentPragmasRegex)
const{
612 return Split(StringRef::npos, 0);
618voidBreakableBlockComment::adjustWhitespace(
unsignedLineIndex,
625 size_tEndOfPreviousLine =
Lines[LineIndex - 1].size();
631 Lines[LineIndex - 1].find_last_not_of(
Blanks, EndOfPreviousLine);
632 if(EndOfPreviousLine == StringRef::npos)
633EndOfPreviousLine = 0;
637 size_tStartOfLine =
Lines[LineIndex].find_first_not_of(
Blanks);
638 if(StartOfLine == StringRef::npos)
639StartOfLine =
Lines[LineIndex].size();
641StringRef Whitespace =
Lines[LineIndex].substr(0, StartOfLine);
643 size_tPreviousContentOffset =
644 Content[LineIndex - 1].data() -
Lines[LineIndex - 1].data();
646PreviousContentOffset, EndOfPreviousLine - PreviousContentOffset);
647 Content[LineIndex] =
Lines[LineIndex].substr(StartOfLine);
657StringRef::size_type Length,
658 unsignedStartColumn)
const{
666 unsignedStartColumn)
const{
667 unsignedLineLength =
668UnbreakableTailLength +
670 if(LineIndex + 1 ==
Lines.size()) {
673 boolHasRemainingText = Offset <
Content[LineIndex].size();
674 if(!HasRemainingText) {
675 boolHasDecoration =
Lines[LineIndex].ltrim().starts_with(Decoration);
677LineLength -= Decoration.size();
686 returnIndentAtLineBreak;
690constllvm::StringSet<>
692 "@param",
"@return",
"@returns",
"@throws",
"@type",
"@template",
693 "@see",
"@deprecated",
"@define",
"@exports",
"@mods",
"@private",
702StringRef ContentWithNoDecoration =
Content[LineIndex];
703 if(LineIndex == 0 && ContentWithNoDecoration.starts_with(
"*"))
704ContentWithNoDecoration = ContentWithNoDecoration.substr(1).ltrim(
Blanks);
705StringRef FirstWord = ContentWithNoDecoration.substr(
7060, ContentWithNoDecoration.find_first_of(
Blanks));
715StringRef
Text=
Content[LineIndex].substr(TailOffset);
716StringRef Prefix = Decoration;
720 unsignedLocalIndentAtLineBreak = IndentAtLineBreak;
721 if(LineIndex + 1 ==
Lines.size() &&
725 if(LocalIndentAtLineBreak >= 2)
726LocalIndentAtLineBreak -= 2;
730 unsignedBreakOffsetInToken =
732 unsignedCharsToRemove =
Split.second;
733assert(LocalIndentAtLineBreak >= Prefix.size());
734std::string PrefixWithTrailingIndent = std::string(Prefix);
735PrefixWithTrailingIndent.append(ContentIndent,
' ');
736Whitespaces.replaceWhitespaceInToken(
737 tokenAt(LineIndex), BreakOffsetInToken, CharsToRemove,
"",
739LocalIndentAtLineBreak + ContentIndent -
740PrefixWithTrailingIndent.size());
744 unsignedLineIndex,
constllvm::Regex &CommentPragmasRegex)
const{
745 if(!
mayReflow(LineIndex, CommentPragmasRegex))
746 return Split(StringRef::npos, 0);
750 size_tTrimmed =
Content[LineIndex].find_first_not_of(
Blanks);
753 if(PreviousContentIndent && Trimmed != StringRef::npos &&
754Trimmed != PreviousContentIndent) {
755 return Split(StringRef::npos, 0);
759 return Split(0, Trimmed != StringRef::npos ? Trimmed : 0);
764 returnDelimitersOnNewline &&
765 Lines[0].substr(1).find_first_not_of(
Blanks) != StringRef::npos;
770StringRef TrimmedContent =
Content[LineIndex].ltrim(
Blanks);
773 "Reflowing whitespace within a token");
776 unsignedWhitespaceOffsetInToken =
Content[LineIndex - 1].data() +
777 Content[LineIndex - 1].size() -
779 unsignedWhitespaceLength = TrimmedContent.data() -
781WhitespaceOffsetInToken;
782Whitespaces.replaceWhitespaceInToken(
783 tokenAt(LineIndex), WhitespaceOffsetInToken,
784WhitespaceLength,
"",
791 if(LineIndex == 0) {
792 if(DelimitersOnNewline) {
797 size_tBreakLength =
Lines[0].substr(1).find_first_not_of(
Blanks);
798 if(BreakLength != StringRef::npos) {
807StringRef Prefix = Decoration;
808 if(
Content[LineIndex].empty()) {
809 if(LineIndex + 1 ==
Lines.size()) {
810 if(!LastLineNeedsDecoration) {
815}
else if(!Decoration.empty()) {
818Prefix = Prefix.substr(0, 1);
822Prefix = Prefix.substr(0, 1);
826 unsignedWhitespaceOffsetInToken =
Content[LineIndex - 1].data() +
827 Content[LineIndex - 1].size() -
829 unsignedWhitespaceLength =
Content[LineIndex].data() -
831WhitespaceOffsetInToken;
832Whitespaces.replaceWhitespaceInToken(
833 tokenAt(LineIndex), WhitespaceOffsetInToken, WhitespaceLength,
"", Prefix,
839 if(DelimitersOnNewline) {
843StringRef
Line=
Content.back().substr(TailOffset);
844StringRef TrimmedLine =
Line.rtrim(
Blanks);
845 if(!TrimmedLine.empty())
846 return Split(TrimmedLine.size(),
Line.size() - TrimmedLine.size());
848 return Split(StringRef::npos, 0);
852 unsignedLineIndex,
constllvm::Regex &CommentPragmasRegex)
const{
855StringRef IndentContent =
Content[LineIndex];
856 if(
Lines[LineIndex].ltrim(
Blanks).starts_with(
"*"))
857IndentContent =
Lines[LineIndex].ltrim(
Blanks).substr(1);
859!CommentPragmasRegex.match(IndentContent) &&
868assert(
Tok.
is(TT_LineComment) &&
869 "line comment section must start with a line comment");
874 intFirstLineSpaceChange = 0;
876CurrentTok && CurrentTok->
is(TT_LineComment);
877CurrentTok = CurrentTok->Next) {
878LastLineTok = LineTok;
879StringRef TokenText(CurrentTok->TokenText);
880assert((TokenText.starts_with(
"//") || TokenText.starts_with(
"#")) &&
881 "unsupported line comment prefix, '//' and '#' are supported");
882 size_tFirstLineIndex =
Lines.size();
883TokenText.split(
Lines,
"\n");
886PrefixSpaceChange.resize(
Lines.size());
888Prefix.resize(
Lines.size());
889OriginalPrefix.resize(
Lines.size());
890 for(
size_ti = FirstLineIndex, e =
Lines.size(); i < e; ++i) {
893OriginalPrefix[i] = IndentPrefix;
894 const intSpacesInPrefix = llvm::count(IndentPrefix,
' ');
898 const autoNoSpaceBeforeFirstCommentChar = [&]() {
899assert(
Lines[i].size() > IndentPrefix.size());
900 const charFirstCommentChar =
Lines[i][IndentPrefix.size()];
901 const unsignedFirstCharByteSize =
904 Lines[i].substr(IndentPrefix.size(), FirstCharByteSize),
917 if(FirstCommentChar ==
'#'&& !TokenText.starts_with(
"#"))
919 returnFirstCommentChar ==
'\\'||
isPunctuation(FirstCommentChar) ||
928 if(i == 0 || OriginalPrefix[i].rtrim(
Blanks) !=
929OriginalPrefix[i - 1].rtrim(
Blanks)) {
930 if(SpacesInPrefix < Minimum &&
Lines[i].size() > IndentPrefix.size() &&
931!NoSpaceBeforeFirstCommentChar()) {
932FirstLineSpaceChange = Minimum - SpacesInPrefix;
933}
else if(
static_cast<unsigned>(SpacesInPrefix) >
935FirstLineSpaceChange =
938FirstLineSpaceChange = 0;
942 if(
Lines[i].size() != IndentPrefix.size()) {
943PrefixSpaceChange[i] = FirstLineSpaceChange;
945 if(SpacesInPrefix + PrefixSpaceChange[i] < Minimum) {
946PrefixSpaceChange[i] +=
947Minimum - (SpacesInPrefix + PrefixSpaceChange[i]);
950assert(
Lines[i].size() > IndentPrefix.size());
951 const autoFirstNonSpace =
Lines[i][IndentPrefix.size()];
953 const boolLineRequiresLeadingSpace =
954!NoSpaceBeforeFirstCommentChar() ||
955(FirstNonSpace ==
'}'&& FirstLineSpaceChange != 0);
956 const boolAllowsSpaceChange =
958(SpacesInPrefix != 0 || LineRequiresLeadingSpace);
960 if(PrefixSpaceChange[i] > 0 && AllowsSpaceChange) {
961Prefix[i] = IndentPrefix.str();
962Prefix[i].append(PrefixSpaceChange[i],
' ');
963}
else if(PrefixSpaceChange[i] < 0 && AllowsSpaceChange) {
964Prefix[i] = IndentPrefix
965.drop_back(std::min<std::size_t>(
966-PrefixSpaceChange[i], SpacesInPrefix))
969Prefix[i] = IndentPrefix.str();
974Prefix[i] = IndentPrefix.drop_back(SpacesInPrefix).str();
985 if(EndOfLine == StringRef::npos)
986EndOfLine =
Content[i].size();
991LineTok = CurrentTok->
Next;
992 if(CurrentTok->Next && !CurrentTok->Next->ContinuesLineCommentSection) {
1014StringRef::size_type Length,
1015 unsignedStartColumn)
const{
1028 unsignedLineIndex,
unsignedTailOffset,
Split Split,
1030StringRef
Text=
Content[LineIndex].substr(TailOffset);
1033 unsignedBreakOffsetInToken =
1035 unsignedCharsToRemove =
Split.second;
1036Whitespaces.replaceWhitespaceInToken(
1037 tokenAt(LineIndex), BreakOffsetInToken, CharsToRemove,
"",
1043 unsignedLineIndex,
constllvm::Regex &CommentPragmasRegex)
const{
1044 if(!
mayReflow(LineIndex, CommentPragmasRegex))
1045 return Split(StringRef::npos, 0);
1047 size_tTrimmed =
Content[LineIndex].find_first_not_of(
Blanks);
1053 return Split(0, Trimmed != StringRef::npos ? Trimmed : 0);
1058 if(LineIndex > 0 &&
Tokens[LineIndex] !=
Tokens[LineIndex - 1]) {
1061Whitespaces.replaceWhitespace(
1062*
Tokens[LineIndex],
0,
0,
1065}
else if(LineIndex > 0) {
1076 unsignedOffset =
Lines[LineIndex - 1].data() +
1077 Lines[LineIndex - 1].size() -
1081 unsignedWhitespaceLength =
1083Whitespaces.replaceWhitespaceInToken(*
Tokens[LineIndex], Offset,
1094 unsignedWhitespaceLength =
1096Whitespaces.replaceWhitespaceInToken(*
Tokens[LineIndex], Offset,
1113 if(LineIndex > 0 &&
Tokens[LineIndex] !=
Tokens[LineIndex - 1]) {
1119 unsignedLineColumn =
1121(
Content[LineIndex].data() -
Lines[LineIndex].data()) +
1122(OriginalPrefix[LineIndex].size() - Prefix[LineIndex].size());
1128Whitespaces.replaceWhitespace(*
Tokens[LineIndex],
1135 if(OriginalPrefix[LineIndex] != Prefix[LineIndex]) {
1137 const autoSpacesToRemove = -std::min(PrefixSpaceChange[LineIndex], 0);
1138 const autoSpacesToAdd = std::max(PrefixSpaceChange[LineIndex], 0);
1139Whitespaces.replaceWhitespaceInToken(
1140 tokenAt(LineIndex), OriginalPrefix[LineIndex].size() - SpacesToRemove,
1141SpacesToRemove,
"",
"",
false,
1148State.NextToken = LastLineTok->
Next;
1152 unsignedLineIndex,
constllvm::Regex &CommentPragmasRegex)
const{
1155StringRef IndentContent =
Content[LineIndex];
1156 if(
Lines[LineIndex].starts_with(
"//"))
1157IndentContent =
Lines[LineIndex].substr(2);
1165!CommentPragmasRegex.match(IndentContent) &&
1168OriginalPrefix[LineIndex] == OriginalPrefix[LineIndex - 1];
Declares BreakableToken, BreakableStringLiteral, BreakableComment, BreakableBlockComment and Breakabl...
This file implements an indenter that manages the indentation of continuations.
Various functions to configurably format source code.
Token - This structure provides full information about a lexed token.
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {....
BreakableStringLiteralUsingOperators(const FormatToken &Tok, QuoteStyleType QuoteStyle, bool UnindentPlus, unsigned StartColumn, unsigned UnbreakableTailLength, bool InPPDirective, encoding::Encoding Encoding, const FormatStyle &Style)
Creates a breakable token for a single line string literal for C#, Java, JavaScript,...
QuoteStyleType QuoteStyle
void insertBreak(unsigned LineIndex, unsigned TailOffset, Split Split, unsigned ContentIndent, WhitespaceManager &Whitespaces) const override
Emits the previously retrieved Split via Whitespaces.
StringRef RightBraceQuote
unsigned getContentStartColumn(unsigned LineIndex, bool Break) const override
Returns the column at which content in line LineIndex starts, assuming no reflow.
void updateAfterBroken(WhitespaceManager &Whitespaces) const override
Adds replacements that are needed when the token is broken.
unsigned getRemainingLength(unsigned LineIndex, unsigned Offset, unsigned StartColumn) const override
Returns the number of columns required to format the text following the byte Offset in the line LineI...
Split getSplit(unsigned LineIndex, unsigned TailOffset, unsigned ColumnLimit, unsigned ContentStartColumn, const llvm::Regex &CommentPragmasRegex) const override
Returns a range (offset, length) at which to break the line at LineIndex, if previously broken at Tai...
unsigned UnbreakableTailLength
unsigned getRangeLength(unsigned LineIndex, unsigned Offset, StringRef::size_type Length, unsigned StartColumn) const override
Returns the number of columns required to format the text in the byte range [Offset,...
unsigned getContentStartColumn(unsigned LineIndex, bool Break) const override
Returns the column at which content in line LineIndex starts, assuming no reflow.
unsigned getLineCount() const override
Returns the number of lines in this token in the original code.
unsigned getRemainingLength(unsigned LineIndex, unsigned Offset, unsigned StartColumn) const override
Returns the number of columns required to format the text following the byte Offset in the line LineI...
BreakableStringLiteral(const FormatToken &Tok, unsigned StartColumn, StringRef Prefix, StringRef Postfix, unsigned UnbreakableTailLength, bool InPPDirective, encoding::Encoding Encoding, const FormatStyle &Style)
Creates a breakable token for a single line string literal.
void insertBreak(unsigned LineIndex, unsigned TailOffset, Split Split, unsigned ContentIndent, WhitespaceManager &Whitespaces) const override
Emits the previously retrieved Split via Whitespaces.
Base class for tokens / ranges of tokens that can allow breaking within the tokens - for example,...
std::pair< StringRef::size_type, unsigned > Split
Contains starting character index and length of split.
const FormatStyle & Style
unsigned getLengthAfterCompression(unsigned RemainingTokenColumns, Split Split) const
Returns the number of columns needed to format RemainingTokenColumns, assuming that Split is within t...
const encoding::Encoding Encoding
Manages the whitespaces around tokens and their replacements.
unsigned columnWidthWithTabs(StringRef Text, unsigned StartColumn, unsigned TabWidth, Encoding Encoding)
Returns the number of columns required to display the Text, starting from the StartColumn on a termin...
unsigned getEscapeSequenceLength(StringRef Text)
Gets the length of an escape sequence inside a C++ string literal.
unsigned getCodePointNumBytes(char FirstChar, Encoding Encoding)
Gets the number of bytes in a sequence representing a single codepoint and starting with FirstChar in...
unsigned columnWidth(StringRef Text, Encoding Encoding)
Returns the number of columns required to display the Text on a generic Unicode-capable terminal.
static constexpr StringRef Blanks
bool switchesFormatting(const FormatToken &Token)
Checks if Token switches formatting, like /* clang-format off *â/.
static bool IsBlank(char C)
static BreakableToken::Split getStringSplit(StringRef Text, unsigned UsedColumns, unsigned ColumnLimit, unsigned TabWidth, encoding::Encoding Encoding)
static StringRef getLineCommentIndentPrefix(StringRef Comment, const FormatStyle &Style)
static bool mayReflowContent(StringRef Content)
static BreakableToken::Split getCommentSplit(StringRef Text, unsigned ContentStartColumn, unsigned ColumnLimit, unsigned TabWidth, encoding::Encoding Encoding, const FormatStyle &Style, bool DecorationEndsWithStar=false)
The JSON file list parser is used to communicate input to InstallAPI.
LLVM_READONLY bool isAlphanumeric(unsigned char c)
Return true if this character is an ASCII letter or digit: [a-zA-Z0-9].
LLVM_READONLY bool isHorizontalWhitespace(unsigned char c)
Returns true if this character is horizontal ASCII whitespace: ' ', '\t', '\f', '\v'.
LLVM_READONLY bool isPunctuation(unsigned char c)
Return true if this character is an ASCII punctuation character.
bool Other
Put a space in parentheses not covered by preceding options.
The FormatStyle is used to configure the formatting to follow specific guidelines.
unsigned ContinuationIndentWidth
Indent width for line continuations.
@ LK_Java
Should be used for Java.
@ LK_TextProto
Should be used for Protocol Buffer messages in text format (https://developers.google....
bool Cpp11BracedListStyle
If true, format braced lists as best suited for C++11 braced lists.
BinaryOperatorStyle BreakBeforeBinaryOperators
The way to wrap binary operators.
@ BOS_None
Break after operators.
LanguageKind Language
Language, this format style is targeted at.
unsigned TabWidth
The number of columns used for tab stops.
OperandAlignmentStyle AlignOperands
If true, horizontally align operands of binary and ternary expressions.
SpacesInParensCustom SpacesInParensOptions
Control of individual spaces in parentheses.
SpacesInLineComment SpacesInLineCommentPrefix
How many spaces are allowed at the start of a line comment.
bool isJavaScript() const
@ OAS_AlignAfterOperator
Horizontally align operands of binary and ternary expressions.
unsigned ColumnLimit
The column limit.
A wrapper around a Token storing information about the whitespace characters preceding it.
StringRef TokenText
The raw text of the token.
unsigned Finalized
If true, this token has been fully formatted (indented and potentially re-formatted inside),...
FormatToken * Next
The next token in the unwrapped line.
bool is(tok::TokenKind Kind) const
The current state when indenting a unwrapped line.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4