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

Side by Side Diff: base/string_util.cc

Issue 113996: Move a few functions commonly called with char* to StringPiece. (Closed)
Patch Set: Created 11 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
« base/file_path.h ('K') | « base/string_util.h ('k') | no next file » | 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/string_util.h" 5 #include "base/string_util.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #include <ctype.h> 9 #include <ctype.h>
10 #include <errno.h> 10 #include <errno.h>
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 459
460 result.resize(chars_written); 460 result.resize(chars_written);
461 return result; 461 return result;
462 } 462 }
463 463
464 std::string WideToASCII(const std::wstring& wide) { 464 std::string WideToASCII(const std::wstring& wide) {
465 DCHECK(IsStringASCII(wide)); 465 DCHECK(IsStringASCII(wide));
466 return std::string(wide.begin(), wide.end()); 466 return std::string(wide.begin(), wide.end());
467 } 467 }
468 468
469 std::wstring ASCIIToWide(const std::string& ascii) { 469 std::wstring ASCIIToWide(const StringPiece& ascii) {
470 DCHECK(IsStringASCII(ascii)); 470 DCHECK(IsStringASCII(ascii));
471 return std::wstring(ascii.begin(), ascii.end()); 471 return std::wstring(ascii.begin(), ascii.end());
472 } 472 }
473 473
474 std::string UTF16ToASCII(const string16& utf16) { 474 std::string UTF16ToASCII(const string16& utf16) {
475 DCHECK(IsStringASCII(utf16)); 475 DCHECK(IsStringASCII(utf16));
476 return std::string(utf16.begin(), utf16.end()); 476 return std::string(utf16.begin(), utf16.end());
477 } 477 }
478 478
479 string16 ASCIIToUTF16(const std::string& ascii) { 479 string16 ASCIIToUTF16(const StringPiece& ascii) {
480 DCHECK(IsStringASCII(ascii)); 480 DCHECK(IsStringASCII(ascii));
481 return string16(ascii.begin(), ascii.end()); 481 return string16(ascii.begin(), ascii.end());
482 } 482 }
483 483
484 // Latin1 is just the low range of Unicode, so we can copy directly to convert. 484 // Latin1 is just the low range of Unicode, so we can copy directly to convert.
485 bool WideToLatin1(const std::wstring& wide, std::string* latin1) { 485 bool WideToLatin1(const std::wstring& wide, std::string* latin1) {
486 std::string output; 486 std::string output;
487 output.resize(wide.size()); 487 output.resize(wide.size());
488 latin1->clear(); 488 latin1->clear();
489 for (size_t i = 0; i < wide.size(); i++) { 489 for (size_t i = 0; i < wide.size(); i++) {
(...skipping 26 matching lines...) Expand all
516 bool IsStringASCII(const std::wstring& str) { 516 bool IsStringASCII(const std::wstring& str) {
517 return DoIsStringASCII(str); 517 return DoIsStringASCII(str);
518 } 518 }
519 519
520 #if !defined(WCHAR_T_IS_UTF16) 520 #if !defined(WCHAR_T_IS_UTF16)
521 bool IsStringASCII(const string16& str) { 521 bool IsStringASCII(const string16& str) {
522 return DoIsStringASCII(str); 522 return DoIsStringASCII(str);
523 } 523 }
524 #endif 524 #endif
525 525
526 bool IsStringASCII(const std::string& str) { 526 bool IsStringASCII(const StringPiece& str) {
527 return DoIsStringASCII(str); 527 return DoIsStringASCII(str);
528 } 528 }
529 529
530 // Helper functions that determine whether the given character begins a 530 // Helper functions that determine whether the given character begins a
531 // UTF-8 sequence of bytes with the given length. A character satisfies 531 // UTF-8 sequence of bytes with the given length. A character satisfies
532 // "IsInUTF8Sequence" if it is anything but the first byte in a multi-byte 532 // "IsInUTF8Sequence" if it is anything but the first byte in a multi-byte
533 // character. 533 // character.
534 static inline bool IsBegin2ByteUTF8(int c) { 534 static inline bool IsBegin2ByteUTF8(int c) {
535 return (c & 0xE0) == 0xC0; 535 return (c & 0xE0) == 0xC0;
536 } 536 }
(...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 // Each input byte creates two output hex characters. 1634 // Each input byte creates two output hex characters.
1635 std::string ret(size * 2, '\0'); 1635 std::string ret(size * 2, '\0');
1636 1636
1637 for (size_t i = 0; i < size; ++i) { 1637 for (size_t i = 0; i < size; ++i) {
1638 char b = reinterpret_cast<const char*>(bytes)[i]; 1638 char b = reinterpret_cast<const char*>(bytes)[i];
1639 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; 1639 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf];
1640 ret[(i * 2) + 1] = kHexChars[b & 0xf]; 1640 ret[(i * 2) + 1] = kHexChars[b & 0xf];
1641 } 1641 }
1642 return ret; 1642 return ret;
1643 } 1643 }
OLDNEW
« base/file_path.h ('K') | « base/string_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698