OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/string_escape.h" | 5 #include "base/string_escape.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 | 10 |
11 namespace string_escape { | 11 namespace string_escape { |
12 | 12 |
13 // Try to escape |c| as a "SingleEscapeCharacter" (\n, etc). If successful, | 13 // Try to escape |c| as a "SingleEscapeCharacter" (\n, etc). If successful, |
14 // returns true and appends the escape sequence to |dst|. | 14 // returns true and appends the escape sequence to |dst|. |
15 template<typename CHAR> | 15 template<typename CHAR> |
16 static bool JavascriptSingleEscapeChar(const CHAR c, std::string* dst) { | 16 static bool JavascriptSingleEscapeChar(const CHAR c, std::string* dst) { |
| 17 // WARNING: if you add a new case here, you need to update the reader as well. |
17 switch (c) { | 18 switch (c) { |
18 case '\b': | 19 case '\b': |
19 dst->append("\\b"); | 20 dst->append("\\b"); |
20 break; | 21 break; |
21 case '\f': | 22 case '\f': |
22 dst->append("\\f"); | 23 dst->append("\\f"); |
23 break; | 24 break; |
24 case '\n': | 25 case '\n': |
25 dst->append("\\n"); | 26 dst->append("\\n"); |
26 break; | 27 break; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 90 } |
90 } | 91 } |
91 } | 92 } |
92 | 93 |
93 if (put_in_quotes) | 94 if (put_in_quotes) |
94 dst->push_back('"'); | 95 dst->push_back('"'); |
95 } | 96 } |
96 | 97 |
97 } // namespace string_escape | 98 } // namespace string_escape |
98 | 99 |
OLD | NEW |