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/json/string_escape.h" | |
6 | |
7 #include <string> | 5 #include <string> |
8 | 6 |
| 7 #include "base/string16.h" |
9 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/stringprintf.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 // Try to escape |c| as a "SingleEscapeCharacter" (\n, etc). If successful, | 15 // Try to escape |c| as a "SingleEscapeCharacter" (\n, etc). If successful, |
16 // returns true and appends the escape sequence to |dst|. This isn't required | 16 // returns true and appends the escape sequence to |dst|. This isn't required |
17 // by the spec, but it's more readable by humans than the \uXXXX alternatives. | 17 // by the spec, but it's more readable by humans than the \uXXXX alternatives. |
18 template<typename CHAR> | 18 template<typename CHAR> |
19 static bool JsonSingleEscapeChar(const CHAR c, std::string* dst) { | 19 static bool JsonSingleEscapeChar(const CHAR c, std::string* dst) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 JsonDoubleQuoteT(str, put_in_quotes, dst); | 95 JsonDoubleQuoteT(str, put_in_quotes, dst); |
96 } | 96 } |
97 | 97 |
98 std::string GetDoubleQuotedJson(const string16& str) { | 98 std::string GetDoubleQuotedJson(const string16& str) { |
99 std::string dst; | 99 std::string dst; |
100 JsonDoubleQuote(str, true, &dst); | 100 JsonDoubleQuote(str, true, &dst); |
101 return dst; | 101 return dst; |
102 } | 102 } |
103 | 103 |
104 } // namespace base | 104 } // namespace base |
OLD | NEW |