OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/escape.h" | 5 #include "tools/gn/escape.h" |
6 | 6 |
7 #include "base/containers/stack_container.h" | 7 #include "base/containers/stack_container.h" |
8 | 8 |
9 namespace { | 9 namespace { |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 if (needed_quoting) | 35 if (needed_quoting) |
36 *needed_quoting = true; | 36 *needed_quoting = true; |
37 if (!options.inhibit_quoting) { | 37 if (!options.inhibit_quoting) { |
38 if (!used_quotes) { | 38 if (!used_quotes) { |
39 used_quotes = true; | 39 used_quotes = true; |
40 dest->insert(dest->begin(), '"'); | 40 dest->insert(dest->begin(), '"'); |
41 } | 41 } |
42 } | 42 } |
43 } | 43 } |
44 dest->push_back(' '); | 44 dest->push_back(' '); |
| 45 } else if (str[i] == '\'' && (options.mode & ESCAPE_JSON)) { |
| 46 dest->push_back('\\'); |
| 47 dest->push_back('\''); |
45 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
46 } else if (str[i] == '/' && options.convert_slashes) { | 49 } else if (str[i] == '/' && options.convert_slashes) { |
47 // Convert slashes on Windows if requested. | 50 // Convert slashes on Windows if requested. |
48 dest->push_back('\\'); | 51 dest->push_back('\\'); |
49 #else | 52 #else |
50 } else if (str[i] == '\\' && (options.mode & ESCAPE_SHELL)) { | 53 } else if (str[i] == '\\' && (options.mode & ESCAPE_SHELL)) { |
51 // For non-Windows shell, escape backslashes. | 54 // For non-Windows shell, escape backslashes. |
52 dest->push_back('\\'); | 55 dest->push_back('\\'); |
53 dest->push_back('\\'); | 56 dest->push_back('\\'); |
54 #endif | 57 #endif |
| 58 } else if (str[i] == '\\' && (options.mode & ESCAPE_JSON)) { |
| 59 dest->push_back('\\'); |
| 60 dest->push_back('\\'); |
55 } else { | 61 } else { |
56 dest->push_back(str[i]); | 62 dest->push_back(str[i]); |
57 } | 63 } |
58 } | 64 } |
59 | 65 |
60 if (used_quotes) | 66 if (used_quotes) |
61 dest->push_back('"'); | 67 dest->push_back('"'); |
62 } | 68 } |
63 | 69 |
64 } // namespace | 70 } // namespace |
(...skipping 10 matching lines...) Expand all Loading... |
75 void EscapeStringToStream(std::ostream& out, | 81 void EscapeStringToStream(std::ostream& out, |
76 const base::StringPiece& str, | 82 const base::StringPiece& str, |
77 const EscapeOptions& options) { | 83 const EscapeOptions& options) { |
78 // Escape to a stack buffer and then write out to the stream. | 84 // Escape to a stack buffer and then write out to the stream. |
79 base::StackVector<char, 256> result; | 85 base::StackVector<char, 256> result; |
80 result->reserve(str.size() + 4); // Guess we'll add a couple of extra chars. | 86 result->reserve(str.size() + 4); // Guess we'll add a couple of extra chars. |
81 EscapeStringToString(str, options, &result.container(), NULL); | 87 EscapeStringToString(str, options, &result.container(), NULL); |
82 if (!result->empty()) | 88 if (!result->empty()) |
83 out.write(result->data(), result->size()); | 89 out.write(result->data(), result->size()); |
84 } | 90 } |
OLD | NEW |