forked from OSchip/llvm-project
Preserve carriage return when using clang-format's XML interface.
Patch by James Park. llvm-svn: 196265
This commit is contained in:
parent
907eb5b630
commit
f54dcbc4e6
|
@ -179,6 +179,26 @@ static bool fillRanges(SourceManager &Sources, FileID ID,
|
|||
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 {
|
||||
|
|
Loading…
Reference in New Issue