r196265 - Preserve carriage return when using clang-format's XML interface.
Manuel Klimek
klimek at google.com
Tue Dec 3 01:46:07 PST 2013
Author: klimek
Date: Tue Dec 3 03:46:06 2013
New Revision: 196265
URL: http://llvm.org/viewvc/llvm-project?rev=196265&view=rev
Log:
Preserve carriage return when using clang-format's XML interface.
Patch by James Park.
Modified:
cfe/trunk/tools/clang-format/ClangFormat.cpp
Modified: cfe/trunk/tools/clang-format/ClangFormat.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/ClangFormat.cpp?rev=196265&r1=196264&r2=196265&view=diff
==============================================================================
--- cfe/trunk/tools/clang-format/ClangFormat.cpp (original)
+++ cfe/trunk/tools/clang-format/ClangFormat.cpp Tue Dec 3 03:46:06 2013
@@ -179,6 +179,26 @@ static bool fillRanges(SourceManager &So
return false;
}
+static void outputReplacementXML(StringRef Text) {
+ size_t From = 0;
+ size_t Index;
+ while ((Index = Text.find_first_of("\n\r", From)) != StringRef::npos) {
+ llvm::outs() << Text.substr(From, Index - From);
+ switch (Text[Index]) {
+ case '\n':
+ llvm::outs() << "
";
+ break;
+ case '\r':
+ llvm::outs() << "
";
+ break;
+ default:
+ llvm_unreachable("Unexpected character encountered!");
+ }
+ From = Index + 1;
+ }
+ llvm::outs() << Text.substr(From);
+}
+
// Returns true on error.
static bool format(StringRef FileName) {
FileManager Files((FileSystemOptions()));
@@ -211,8 +231,9 @@ static bool format(StringRef FileName) {
I != E; ++I) {
llvm::outs() << "<replacement "
<< "offset='" << I->getOffset() << "' "
- << "length='" << I->getLength() << "'>"
- << I->getReplacementText() << "</replacement>\n";
+ << "length='" << I->getLength() << "'>";
+ outputReplacementXML(I->getReplacementText());
+ llvm::outs() << "</replacement>\n";
}
llvm::outs() << "</replacements>\n";
} else {
More information about the cfe-commits
mailing list