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

Side by Side Diff: base/json/string_escape.cc

Issue 1180693002: Update from https://crrev.com/333737 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 6 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 | « base/json/json_writer_unittest.cc ('k') | base/logging.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
OLDNEW
« no previous file with comments | « base/json/json_writer_unittest.cc ('k') | base/logging.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698