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

Side by Side Diff: base/i18n/streaming_utf8_validator_perftest.cc

Issue 196793010: Move IsStringASCII/UTF8 to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « base/command_line.cc ('k') | base/strings/string_util.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 // All data that is passed through a WebSocket with type "Text" needs to be 5 // All data that is passed through a WebSocket with type "Text" needs to be
6 // validated as UTF8. Since this is done on the IO thread, it needs to be 6 // validated as UTF8. Since this is done on the IO thread, it needs to be
7 // reasonably fast. 7 // reasonably fast.
8 8
9 // We are only interested in the performance on valid UTF8. Invalid UTF8 will 9 // We are only interested in the performance on valid UTF8. Invalid UTF8 will
10 // result in a connection failure, so is unlikely to become a source of 10 // result in a connection failure, so is unlikely to become a source of
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // the results will not be meaningful with sequences containing 49 // the results will not be meaningful with sequences containing
50 // top-bit-set bytes. 50 // top-bit-set bytes.
51 bool IsString7Bit(const std::string& s) { 51 bool IsString7Bit(const std::string& s) {
52 for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) { 52 for (std::string::const_iterator it = s.begin(); it != s.end(); ++it) {
53 if (*it & 0x80) 53 if (*it & 0x80)
54 return false; 54 return false;
55 } 55 }
56 return true; 56 return true;
57 } 57 }
58 58
59 bool IsStringUTF8(const std::string& s) {
60 return base::IsStringUTF8(s);
61 }
62
59 // Assumes that |previous| is a valid UTF-8 sequence, and attempts to return 63 // Assumes that |previous| is a valid UTF-8 sequence, and attempts to return
60 // the next one. Is just barely smart enough to iterate through the ranges 64 // the next one. Is just barely smart enough to iterate through the ranges
61 // defined about. 65 // defined about.
62 std::string NextUtf8Sequence(const std::string& previous) { 66 std::string NextUtf8Sequence(const std::string& previous) {
63 DCHECK(StreamingUtf8Validator::Validate(previous)); 67 DCHECK(StreamingUtf8Validator::Validate(previous));
64 std::string next = previous; 68 std::string next = previous;
65 for (int i = static_cast<int>(previous.length() - 1); i >= 0; --i) { 69 for (int i = static_cast<int>(previous.length() - 1); i >= 0; --i) {
66 // All bytes in a UTF-8 sequence except the first one are 70 // All bytes in a UTF-8 sequence except the first one are
67 // constrained to the range 0x80 to 0xbf, inclusive. When we 71 // constrained to the range 0x80 to 0xbf, inclusive. When we
68 // increment past 0xbf, we carry into the previous byte. 72 // increment past 0xbf, we carry into the previous byte.
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 RunSomeTests("%s: bytes=4 ranged length=%d repeat=%d", 229 RunSomeTests("%s: bytes=4 ranged length=%d repeat=%d",
226 base::Bind(ConstructRangedTestString, 230 base::Bind(ConstructRangedTestString,
227 kFourByteSeqRangeStart, 231 kFourByteSeqRangeStart,
228 kFourByteSeqRangeEnd), 232 kFourByteSeqRangeEnd),
229 kTestFunctions, 233 kTestFunctions,
230 2); 234 2);
231 } 235 }
232 236
233 } // namespace 237 } // namespace
234 } // namespace base 238 } // namespace base
OLDNEW
« no previous file with comments | « base/command_line.cc ('k') | base/strings/string_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698