aboutsummaryrefslogtreecommitdiff
path: root/clang-format
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2013-02-06 09:42:05 +0000
committerManuel Klimek <klimek@google.com>2013-02-06 09:42:05 +0000
commitf1a25ed6fc6d964b31f957094916c18671f694d0 (patch)
treed153cfa226ef633d84a9d9289d7c3001ee2c5b10 /clang-format
parent0fe1e723b1c20525b56ce68ff6e2b5a7f4cdd9cb (diff)
Kick JSON output for XML output.
Apparently the owners of the tools we want to integrate with (eclipse in this case) don't have JSON parsers. The output now is: <replacements> <replacement offset='2' length='3'> </replacement> ... </replacements> Kicking JSON for now - it's easy enough to get back in when we need it. FIXME: once we find this useful enough, we might want to add it as free-standing functions to tooling. git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/trunk@174497 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'clang-format')
-rw-r--r--clang-format/ClangFormat.cpp23
1 files changed, 9 insertions, 14 deletions
diff --git a/clang-format/ClangFormat.cpp b/clang-format/ClangFormat.cpp
index 7b3da2d1..d34f533c 100644
--- a/clang-format/ClangFormat.cpp
+++ b/clang-format/ClangFormat.cpp
@@ -38,8 +38,8 @@ static cl::opt<std::string> Style(
static cl::opt<bool> Inplace("i",
cl::desc("Inplace edit <file>, if specified."));
-static cl::opt<bool> OutputReplacements(
- "output-replacements", cl::desc("Output replacements as JSON."));
+static cl::opt<bool> OutputXML(
+ "output-replacements-xml", cl::desc("Output replacements as XML."));
// FIXME: Remove this when styles are configurable through files.
static cl::opt<bool> InvertPointerBinding(
@@ -107,22 +107,17 @@ static void format() {
Ranges.push_back(CharSourceRange::getCharRange(Start, End));
}
tooling::Replacements Replaces = reformat(getStyle(), Lex, Sources, Ranges);
- if (OutputReplacements) {
- llvm::outs() << "[\n";
+ if (OutputXML) {
+ llvm::outs() << "<?xml version='1.0'?>\n<replacements>\n";
for (tooling::Replacements::const_iterator I = Replaces.begin(),
E = Replaces.end();
I != E; ++I) {
- if (I != Replaces.begin()) {
- llvm::outs() << ",\n";
- }
- llvm::outs() << " {\n"
- << " \"offset\": " << I->getOffset() << ",\n"
- << " \"length\": " << I->getLength() << ",\n"
- << " \"replacement_text\": \"" << I->getReplacementText()
- << "\"\n"
- << " }";
+ llvm::outs() << "<replacement "
+ << "offset='" << I->getOffset() << "' "
+ << "length='" << I->getLength() << "'>"
+ << I->getReplacementText() << "</replacement>\n";
}
- llvm::outs() << "\n]\n";
+ llvm::outs() << "</replacements>\n";
} else {
Rewriter Rewrite(Sources, LangOptions());
tooling::applyAllReplacements(Replaces, Rewrite);