Skip to content

Commit 8dcdde1

Browse files
committed
Group the helpers for word wrapping with the primary routine. No
functionality changed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@140523 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 56e0311 commit 8dcdde1

File tree

1 file changed

+92
-92
lines changed

1 file changed

+92
-92
lines changed

lib/Frontend/TextDiagnosticPrinter.cpp

Lines changed: 92 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -763,98 +763,6 @@ class TextDiagnostic {
763763

764764
} // end namespace
765765

766-
/// \brief Skip over whitespace in the string, starting at the given
767-
/// index.
768-
///
769-
/// \returns The index of the first non-whitespace character that is
770-
/// greater than or equal to Idx or, if no such character exists,
771-
/// returns the end of the string.
772-
static unsigned skipWhitespace(unsigned Idx,
773-
const SmallVectorImpl<char> &Str,
774-
unsigned Length) {
775-
while (Idx < Length && isspace(Str[Idx]))
776-
++Idx;
777-
return Idx;
778-
}
779-
780-
/// \brief If the given character is the start of some kind of
781-
/// balanced punctuation (e.g., quotes or parentheses), return the
782-
/// character that will terminate the punctuation.
783-
///
784-
/// \returns The ending punctuation character, if any, or the NULL
785-
/// character if the input character does not start any punctuation.
786-
static inline char findMatchingPunctuation(char c) {
787-
switch (c) {
788-
case '\'': return '\'';
789-
case '`': return '\'';
790-
case '"': return '"';
791-
case '(': return ')';
792-
case '[': return ']';
793-
case '{': return '}';
794-
default: break;
795-
}
796-
797-
return 0;
798-
}
799-
800-
/// \brief Find the end of the word starting at the given offset
801-
/// within a string.
802-
///
803-
/// \returns the index pointing one character past the end of the
804-
/// word.
805-
static unsigned findEndOfWord(unsigned Start,
806-
const SmallVectorImpl<char> &Str,
807-
unsigned Length, unsigned Column,
808-
unsigned Columns) {
809-
assert(Start < Str.size() && "Invalid start position!");
810-
unsigned End = Start + 1;
811-
812-
// If we are already at the end of the string, take that as the word.
813-
if (End == Str.size())
814-
return End;
815-
816-
// Determine if the start of the string is actually opening
817-
// punctuation, e.g., a quote or parentheses.
818-
char EndPunct = findMatchingPunctuation(Str[Start]);
819-
if (!EndPunct) {
820-
// This is a normal word. Just find the first space character.
821-
while (End < Length && !isspace(Str[End]))
822-
++End;
823-
return End;
824-
}
825-
826-
// We have the start of a balanced punctuation sequence (quotes,
827-
// parentheses, etc.). Determine the full sequence is.
828-
llvm::SmallString<16> PunctuationEndStack;
829-
PunctuationEndStack.push_back(EndPunct);
830-
while (End < Length && !PunctuationEndStack.empty()) {
831-
if (Str[End] == PunctuationEndStack.back())
832-
PunctuationEndStack.pop_back();
833-
else if (char SubEndPunct = findMatchingPunctuation(Str[End]))
834-
PunctuationEndStack.push_back(SubEndPunct);
835-
836-
++End;
837-
}
838-
839-
// Find the first space character after the punctuation ended.
840-
while (End < Length && !isspace(Str[End]))
841-
++End;
842-
843-
unsigned PunctWordLength = End - Start;
844-
if (// If the word fits on this line
845-
Column + PunctWordLength <= Columns ||
846-
// ... or the word is "short enough" to take up the next line
847-
// without too much ugly white space
848-
PunctWordLength < Columns/3)
849-
return End; // Take the whole thing as a single "word".
850-
851-
// The whole quoted/parenthesized string is too long to print as a
852-
// single "word". Instead, find the "word" that starts just after
853-
// the punctuation and use that end-point instead. This will recurse
854-
// until it finds something small enough to consider a word.
855-
return findEndOfWord(Start + 1, Str, Length, Column + 1, Columns);
856-
}
857-
858766
/// Get the presumed location of a diagnostic message. This computes the
859767
/// presumed location for the top of any macro backtrace when present.
860768
static PresumedLoc getDiagnosticPresumedLoc(const SourceManager &SM,
@@ -1082,6 +990,98 @@ static void printDiagnosticOptions(raw_ostream &OS,
1082990
OS << ']';
1083991
}
1084992

993+
/// \brief Skip over whitespace in the string, starting at the given
994+
/// index.
995+
///
996+
/// \returns The index of the first non-whitespace character that is
997+
/// greater than or equal to Idx or, if no such character exists,
998+
/// returns the end of the string.
999+
static unsigned skipWhitespace(unsigned Idx,
1000+
const SmallVectorImpl<char> &Str,
1001+
unsigned Length) {
1002+
while (Idx < Length && isspace(Str[Idx]))
1003+
++Idx;
1004+
return Idx;
1005+
}
1006+
1007+
/// \brief If the given character is the start of some kind of
1008+
/// balanced punctuation (e.g., quotes or parentheses), return the
1009+
/// character that will terminate the punctuation.
1010+
///
1011+
/// \returns The ending punctuation character, if any, or the NULL
1012+
/// character if the input character does not start any punctuation.
1013+
static inline char findMatchingPunctuation(char c) {
1014+
switch (c) {
1015+
case '\'': return '\'';
1016+
case '`': return '\'';
1017+
case '"': return '"';
1018+
case '(': return ')';
1019+
case '[': return ']';
1020+
case '{': return '}';
1021+
default: break;
1022+
}
1023+
1024+
return 0;
1025+
}
1026+
1027+
/// \brief Find the end of the word starting at the given offset
1028+
/// within a string.
1029+
///
1030+
/// \returns the index pointing one character past the end of the
1031+
/// word.
1032+
static unsigned findEndOfWord(unsigned Start,
1033+
const SmallVectorImpl<char> &Str,
1034+
unsigned Length, unsigned Column,
1035+
unsigned Columns) {
1036+
assert(Start < Str.size() && "Invalid start position!");
1037+
unsigned End = Start + 1;
1038+
1039+
// If we are already at the end of the string, take that as the word.
1040+
if (End == Str.size())
1041+
return End;
1042+
1043+
// Determine if the start of the string is actually opening
1044+
// punctuation, e.g., a quote or parentheses.
1045+
char EndPunct = findMatchingPunctuation(Str[Start]);
1046+
if (!EndPunct) {
1047+
// This is a normal word. Just find the first space character.
1048+
while (End < Length && !isspace(Str[End]))
1049+
++End;
1050+
return End;
1051+
}
1052+
1053+
// We have the start of a balanced punctuation sequence (quotes,
1054+
// parentheses, etc.). Determine the full sequence is.
1055+
llvm::SmallString<16> PunctuationEndStack;
1056+
PunctuationEndStack.push_back(EndPunct);
1057+
while (End < Length && !PunctuationEndStack.empty()) {
1058+
if (Str[End] == PunctuationEndStack.back())
1059+
PunctuationEndStack.pop_back();
1060+
else if (char SubEndPunct = findMatchingPunctuation(Str[End]))
1061+
PunctuationEndStack.push_back(SubEndPunct);
1062+
1063+
++End;
1064+
}
1065+
1066+
// Find the first space character after the punctuation ended.
1067+
while (End < Length && !isspace(Str[End]))
1068+
++End;
1069+
1070+
unsigned PunctWordLength = End - Start;
1071+
if (// If the word fits on this line
1072+
Column + PunctWordLength <= Columns ||
1073+
// ... or the word is "short enough" to take up the next line
1074+
// without too much ugly white space
1075+
PunctWordLength < Columns/3)
1076+
return End; // Take the whole thing as a single "word".
1077+
1078+
// The whole quoted/parenthesized string is too long to print as a
1079+
// single "word". Instead, find the "word" that starts just after
1080+
// the punctuation and use that end-point instead. This will recurse
1081+
// until it finds something small enough to consider a word.
1082+
return findEndOfWord(Start + 1, Str, Length, Column + 1, Columns);
1083+
}
1084+
10851085
/// \brief Print the given string to a stream, word-wrapping it to
10861086
/// some number of columns in the process.
10871087
///

0 commit comments

Comments
 (0)