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

Side by Side Diff: base/strings/string_util.h

Issue 543043002: Implement fast path in UTF8ToUTF16 for pure ASCII strings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 6 years, 2 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 | « no previous file | base/strings/string_util.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 // This file defines utility functions for working with strings. 5 // This file defines utility functions for working with strings.
6 6
7 #ifndef BASE_STRINGS_STRING_UTIL_H_ 7 #ifndef BASE_STRINGS_STRING_UTIL_H_
8 #define BASE_STRINGS_STRING_UTIL_H_ 8 #define BASE_STRINGS_STRING_UTIL_H_
9 9
10 #include <ctype.h> 10 #include <ctype.h>
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 // string be 8-bit or UTF8? It contains only characters that are < 256 (in the 238 // string be 8-bit or UTF8? It contains only characters that are < 256 (in the
239 // first case) or characters that use only 8-bits and whose 8-bit 239 // first case) or characters that use only 8-bits and whose 8-bit
240 // representation looks like a UTF-8 string (the second case). 240 // representation looks like a UTF-8 string (the second case).
241 // 241 //
242 // Note that IsStringUTF8 checks not only if the input is structurally 242 // Note that IsStringUTF8 checks not only if the input is structurally
243 // valid but also if it doesn't contain any non-character codepoint 243 // valid but also if it doesn't contain any non-character codepoint
244 // (e.g. U+FFFE). It's done on purpose because all the existing callers want 244 // (e.g. U+FFFE). It's done on purpose because all the existing callers want
245 // to have the maximum 'discriminating' power from other encodings. If 245 // to have the maximum 'discriminating' power from other encodings. If
246 // there's a use case for just checking the structural validity, we have to 246 // there's a use case for just checking the structural validity, we have to
247 // add a new function for that. 247 // add a new function for that.
248 //
249 // IsStringASCII assumes the input is likely all ASCII, and does not leave early
250 // if it is not the case.
248 BASE_EXPORT bool IsStringUTF8(const std::string& str); 251 BASE_EXPORT bool IsStringUTF8(const std::string& str);
249 BASE_EXPORT bool IsStringASCII(const StringPiece& str); 252 BASE_EXPORT bool IsStringASCII(const StringPiece& str);
253 BASE_EXPORT bool IsStringASCII(const StringPiece16& str);
254 // A convenience adaptor for WebStrings, as they don't convert into
255 // StringPieces directly.
250 BASE_EXPORT bool IsStringASCII(const string16& str); 256 BASE_EXPORT bool IsStringASCII(const string16& str);
251 257
252 // Converts the elements of the given string. This version uses a pointer to 258 // Converts the elements of the given string. This version uses a pointer to
253 // clearly differentiate it from the non-pointer variant. 259 // clearly differentiate it from the non-pointer variant.
254 template <class str> inline void StringToLowerASCII(str* s) { 260 template <class str> inline void StringToLowerASCII(str* s) {
255 for (typename str::iterator i = s->begin(); i != s->end(); ++i) 261 for (typename str::iterator i = s->begin(); i != s->end(); ++i)
256 *i = ToLowerASCII(*i); 262 *i = ToLowerASCII(*i);
257 } 263 }
258 264
259 template <class str> inline str StringToLowerASCII(const str& s) { 265 template <class str> inline str StringToLowerASCII(const str& s) {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 #elif defined(WCHAR_T_IS_UTF32) 520 #elif defined(WCHAR_T_IS_UTF32)
515 typedef uint32 Unsigned; 521 typedef uint32 Unsigned;
516 #endif 522 #endif
517 }; 523 };
518 template<> 524 template<>
519 struct ToUnsigned<short> { 525 struct ToUnsigned<short> {
520 typedef unsigned short Unsigned; 526 typedef unsigned short Unsigned;
521 }; 527 };
522 528
523 #endif // BASE_STRINGS_STRING_UTIL_H_ 529 #endif // BASE_STRINGS_STRING_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/strings/string_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698