| 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" | 5 #include "base/json/string_escape.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 128 } |
| 129 | 129 |
| 130 std::string EscapeBytesAsInvalidJSONString(const StringPiece& str, | 130 std::string EscapeBytesAsInvalidJSONString(const StringPiece& str, |
| 131 bool put_in_quotes) { | 131 bool put_in_quotes) { |
| 132 std::string dest; | 132 std::string dest; |
| 133 | 133 |
| 134 if (put_in_quotes) | 134 if (put_in_quotes) |
| 135 dest.push_back('"'); | 135 dest.push_back('"'); |
| 136 | 136 |
| 137 for (StringPiece::const_iterator it = str.begin(); it != str.end(); ++it) { | 137 for (StringPiece::const_iterator it = str.begin(); it != str.end(); ++it) { |
| 138 ToUnsigned<StringPiece::value_type>::Unsigned c = *it; | 138 unsigned char c = *it; |
| 139 if (EscapeSpecialCodePoint(c, &dest)) | 139 if (EscapeSpecialCodePoint(c, &dest)) |
| 140 continue; | 140 continue; |
| 141 | 141 |
| 142 if (c < 32 || c > 126) | 142 if (c < 32 || c > 126) |
| 143 base::StringAppendF(&dest, kU16EscapeFormat, c); | 143 base::StringAppendF(&dest, kU16EscapeFormat, c); |
| 144 else | 144 else |
| 145 dest.push_back(*it); | 145 dest.push_back(*it); |
| 146 } | 146 } |
| 147 | 147 |
| 148 if (put_in_quotes) | 148 if (put_in_quotes) |
| 149 dest.push_back('"'); | 149 dest.push_back('"'); |
| 150 | 150 |
| 151 return dest; | 151 return dest; |
| 152 } | 152 } |
| 153 | 153 |
| 154 } // namespace base | 154 } // namespace base |
| OLD | NEW |