aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Format/WhitespaceManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r--clang/lib/Format/WhitespaceManager.cpp49
1 files changed, 24 insertions, 25 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index 0f46e62..4138442 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -221,14 +221,14 @@ void WhitespaceManager::generateChanges() {
for (unsigned i = 0, e = Changes.size(); i != e; ++i) {
const Change &C = Changes[i];
if (C.CreateReplacement) {
- std::string ReplacementText =
- C.PreviousLinePostfix +
- (C.ContinuesPPDirective
- ? getNewlineText(C.NewlinesBefore, C.Spaces,
- C.PreviousEndOfTokenColumn,
- C.EscapedNewlineColumn)
- : getNewlineText(C.NewlinesBefore, C.Spaces)) +
- C.CurrentLinePrefix;
+ std::string ReplacementText = C.PreviousLinePostfix;
+ if (C.ContinuesPPDirective)
+ appendNewlineText(ReplacementText, C.NewlinesBefore,
+ C.PreviousEndOfTokenColumn, C.EscapedNewlineColumn);
+ else
+ appendNewlineText(ReplacementText, C.NewlinesBefore);
+ appendIndentText(ReplacementText, C.Spaces);
+ ReplacementText.append(C.CurrentLinePrefix);
storeReplacement(C.OriginalWhitespaceRange, ReplacementText);
}
}
@@ -246,34 +246,33 @@ void WhitespaceManager::storeReplacement(const SourceRange &Range,
SourceMgr, CharSourceRange::getCharRange(Range), Text));
}
-std::string WhitespaceManager::getNewlineText(unsigned Newlines,
- unsigned Spaces) {
- return std::string(Newlines, '\n') + getIndentText(Spaces);
+void WhitespaceManager::appendNewlineText(std::string &Text,
+ unsigned Newlines) {
+ for (unsigned i = 0; i < Newlines; ++i)
+ Text.append(UseCRLF ? "\r\n" : "\n");
}
-std::string WhitespaceManager::getNewlineText(unsigned Newlines,
- unsigned Spaces,
- unsigned PreviousEndOfTokenColumn,
- unsigned EscapedNewlineColumn) {
- std::string NewlineText;
+void WhitespaceManager::appendNewlineText(std::string &Text, unsigned Newlines,
+ unsigned PreviousEndOfTokenColumn,
+ unsigned EscapedNewlineColumn) {
if (Newlines > 0) {
unsigned Offset =
std::min<int>(EscapedNewlineColumn - 1, PreviousEndOfTokenColumn);
for (unsigned i = 0; i < Newlines; ++i) {
- NewlineText += std::string(EscapedNewlineColumn - Offset - 1, ' ');
- NewlineText += "\\\n";
+ Text.append(std::string(EscapedNewlineColumn - Offset - 1, ' '));
+ Text.append(UseCRLF ? "\\\r\n" : "\\\n");
Offset = 0;
}
}
- return NewlineText + getIndentText(Spaces);
}
-std::string WhitespaceManager::getIndentText(unsigned Spaces) {
- if (!Style.UseTab)
- return std::string(Spaces, ' ');
-
- return std::string(Spaces / Style.TabWidth, '\t') +
- std::string(Spaces % Style.TabWidth, ' ');
+void WhitespaceManager::appendIndentText(std::string &Text, unsigned Spaces) {
+ if (!Style.UseTab) {
+ Text.append(std::string(Spaces, ' '));
+ } else {
+ Text.append(std::string(Spaces / Style.TabWidth, '\t'));
+ Text.append(std::string(Spaces % Style.TabWidth, ' '));
+ }
}
} // namespace format