Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: tools/gn/visual_studio_writer.cc

Issue 2803613003: "Escape" certain characters (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "tools/gn/visual_studio_writer.h" 5 #include "tools/gn/visual_studio_writer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 19 matching lines...) Expand all
30 #include "tools/gn/variables.h" 30 #include "tools/gn/variables.h"
31 #include "tools/gn/visual_studio_utils.h" 31 #include "tools/gn/visual_studio_utils.h"
32 #include "tools/gn/xml_element_writer.h" 32 #include "tools/gn/xml_element_writer.h"
33 33
34 #if defined(OS_WIN) 34 #if defined(OS_WIN)
35 #include "base/win/registry.h" 35 #include "base/win/registry.h"
36 #endif 36 #endif
37 37
38 namespace { 38 namespace {
39 39
40 std::string EscapeString(const std::string& value) {
41 std::string result;
42 if (value.find_first_of("<>&\"\t\r\n") != std::string::npos) {
brettw 2017/04/07 18:16:43 I'd delete this check and always do the loop below
kylix_rd 2017/04/07 19:18:53 Done.
43 for (std::string::const_iterator it = value.cbegin();
brettw 2017/04/07 18:16:43 I would have used a range-based for loop here whic
kylix_rd 2017/04/07 19:18:53 Yes, that's better. Done.
44 it != value.cend();
45 ++it) {
46 switch (*it) {
47 case '\n': result += "&#10;"; break;
brucedawson 2017/04/05 18:51:39 Do you have references for the \n, \r, and \t sequ
kylix_rd 2017/04/05 18:55:02 I based it off the code in libxml here: https://cs
48 case '\r': result += "&#13;"; break;
49 case '\t': result += "&#9;"; break;
50 case '"': result += "&quot;"; break;
51 case '<': result += "&lt;"; break;
52 case '>': result += "&gt;"; break;
53 case '&': result += "&amp;"; break;
54 default:
55 result += *it;
56 }
57 }
58 } else
brettw 2017/04/07 18:16:43 Google style says all arms in an if statement shou
59 result = value;
60 return result;
61 }
62
40 struct SemicolonSeparatedWriter { 63 struct SemicolonSeparatedWriter {
41 void operator()(const std::string& value, std::ostream& out) const { 64 void operator()(const std::string& value, std::ostream& out) const {
42 out << value + ';'; 65 out << EscapeString(value) + ';';
43 } 66 }
44 }; 67 };
45 68
46 struct IncludeDirWriter { 69 struct IncludeDirWriter {
47 explicit IncludeDirWriter(PathOutput& path_output) 70 explicit IncludeDirWriter(PathOutput& path_output)
48 : path_output_(path_output) {} 71 : path_output_(path_output) {}
49 ~IncludeDirWriter() = default; 72 ~IncludeDirWriter() = default;
50 73
51 void operator()(const SourceDir& dir, std::ostream& out) const { 74 void operator()(const SourceDir& dir, std::ostream& out) const {
52 path_output_.WriteDir(out, dir, PathOutput::DIR_NO_LAST_SLASH); 75 path_output_.WriteDir(out, dir, PathOutput::DIR_NO_LAST_SLASH);
(...skipping 814 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 } 890 }
868 } 891 }
869 892
870 std::string VisualStudioWriter::GetNinjaTarget(const Target* target) { 893 std::string VisualStudioWriter::GetNinjaTarget(const Target* target) {
871 std::ostringstream ninja_target_out; 894 std::ostringstream ninja_target_out;
872 DCHECK(!target->dependency_output_file().value().empty()); 895 DCHECK(!target->dependency_output_file().value().empty());
873 ninja_path_output_.WriteFile(ninja_target_out, 896 ninja_path_output_.WriteFile(ninja_target_out,
874 target->dependency_output_file()); 897 target->dependency_output_file());
875 return ninja_target_out.str(); 898 return ninja_target_out.str();
876 } 899 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698