<div dir="ltr">So far, it is not as we are only inserting spaces and newlines.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Feb 5, 2013 at 4:56 PM, Dmitri Gribenko <span dir="ltr"><<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Manuel,<br>
<div><div class="h5"><br>
On Tue, Feb 5, 2013 at 5:52 PM, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> wrote:<br>
> Author: klimek<br>
> Date: Tue Feb  5 09:52:21 2013<br>
> New Revision: 174382<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=174382&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=174382&view=rev</a><br>
> Log:<br>
> Adds JSON output for replacements, to simplify tools integration.<br>
><br>
> Using -output-replacements will now output the replacements instead<br>
> of the changed code. This allows easier integration with tools that<br>
> need full control over what changed.<br>
><br>
> The format is an array of objects with the members "offset" (number),<br>
> "length" (number) and "replacement_text" (string), for example:<br>
><br>
> [<br>
>   {<br>
>     "offset": 42,<br>
>     "length": 5,<br>
>     "replacement_text": "  "<br>
>   },<br>
>   {<br>
>     "offset": 105,<br>
>     "length": 4,<br>
>     "replacement_text": ""<br>
>   }<br>
> ]<br>
><br>
> Modified:<br>
>     clang-tools-extra/trunk/clang-format/ClangFormat.cpp<br>
><br>
> Modified: clang-tools-extra/trunk/clang-format/ClangFormat.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-format/ClangFormat.cpp?rev=174382&r1=174381&r2=174382&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-format/ClangFormat.cpp?rev=174382&r1=174381&r2=174382&view=diff</a><br>

> ==============================================================================<br>
> --- clang-tools-extra/trunk/clang-format/ClangFormat.cpp (original)<br>
> +++ clang-tools-extra/trunk/clang-format/ClangFormat.cpp Tue Feb  5 09:52:21 2013<br>
> @@ -38,6 +38,9 @@ static cl::opt<std::string> Style(<br>
>  static cl::opt<bool> Inplace("i",<br>
>                               cl::desc("Inplace edit <file>, if specified."));<br>
><br>
> +static cl::opt<bool> OutputReplacements(<br>
> +    "output-replacements", cl::desc("Output replacements as JSON."));<br>
> +<br>
>  // FIXME: Remove this when styles are configurable through files.<br>
>  static cl::opt<bool> InvertPointerBinding(<br>
>      "invert-pointer-binding", cl::desc("Inverts the side to which */& bind"),<br>
> @@ -104,23 +107,41 @@ static void format() {<br>
>      Ranges.push_back(CharSourceRange::getCharRange(Start, End));<br>
>    }<br>
>    tooling::Replacements Replaces = reformat(getStyle(), Lex, Sources, Ranges);<br>
> -  Rewriter Rewrite(Sources, LangOptions());<br>
> -  tooling::applyAllReplacements(Replaces, Rewrite);<br>
> -  if (Inplace) {<br>
> -    if (Replaces.size() == 0)<br>
> -      return; // Nothing changed, don't touch the file.<br>
> -<br>
> -    std::string ErrorInfo;<br>
> -    llvm::raw_fd_ostream FileStream(FileName.c_str(), ErrorInfo,<br>
> -                                    llvm::raw_fd_ostream::F_Binary);<br>
> -    if (!ErrorInfo.empty()) {<br>
> -      llvm::errs() << "Error while writing file: " << ErrorInfo << "\n";<br>
> -      return;<br>
> +  if (OutputReplacements) {<br>
> +    llvm::outs() << "[\n";<br>
> +    for (tooling::Replacements::const_iterator I = Replaces.begin(),<br>
> +                                               E = Replaces.end();<br>
> +         I != E; ++I) {<br>
> +      if (I != Replaces.begin()) {<br>
> +        llvm::outs() << ",\n";<br>
> +      }<br>
> +      llvm::outs() << "  {\n"<br>
> +                   << "    \"offset\": " << I->getOffset() << ",\n"<br>
> +                   << "    \"length\": " << I->getLength() << ",\n"<br>
> +                   << "    \"replacement_text\": \"" << I->getReplacementText()<br>
<br>
</div></div>Isn't there some escaping required?<br>
<span class="HOEnZb"><font color="#888888"><br>
Dmitri<br>
<br>
--<br>
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>>*/<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>