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

Side by Side Diff: base/string_util.cc

Issue 174110: Print more info in IsStringASCII assertions. (Closed)
Patch Set: Created 11 years, 4 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 | 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 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 bool trim_sequences_with_line_breaks) { 495 bool trim_sequences_with_line_breaks) {
496 return CollapseWhitespaceT(text, trim_sequences_with_line_breaks); 496 return CollapseWhitespaceT(text, trim_sequences_with_line_breaks);
497 } 497 }
498 498
499 std::string CollapseWhitespaceASCII(const std::string& text, 499 std::string CollapseWhitespaceASCII(const std::string& text,
500 bool trim_sequences_with_line_breaks) { 500 bool trim_sequences_with_line_breaks) {
501 return CollapseWhitespaceT(text, trim_sequences_with_line_breaks); 501 return CollapseWhitespaceT(text, trim_sequences_with_line_breaks);
502 } 502 }
503 503
504 std::string WideToASCII(const std::wstring& wide) { 504 std::string WideToASCII(const std::wstring& wide) {
505 DCHECK(IsStringASCII(wide)); 505 DCHECK(IsStringASCII(wide)) << wide;
506 return std::string(wide.begin(), wide.end()); 506 return std::string(wide.begin(), wide.end());
507 } 507 }
508 508
509 std::wstring ASCIIToWide(const StringPiece& ascii) { 509 std::wstring ASCIIToWide(const StringPiece& ascii) {
510 DCHECK(IsStringASCII(ascii)); 510 DCHECK(IsStringASCII(ascii)) << ascii;
511 return std::wstring(ascii.begin(), ascii.end()); 511 return std::wstring(ascii.begin(), ascii.end());
512 } 512 }
513 513
514 std::string UTF16ToASCII(const string16& utf16) { 514 std::string UTF16ToASCII(const string16& utf16) {
515 DCHECK(IsStringASCII(utf16)); 515 DCHECK(IsStringASCII(utf16)) << utf16;
516 return std::string(utf16.begin(), utf16.end()); 516 return std::string(utf16.begin(), utf16.end());
517 } 517 }
518 518
519 string16 ASCIIToUTF16(const StringPiece& ascii) { 519 string16 ASCIIToUTF16(const StringPiece& ascii) {
520 DCHECK(IsStringASCII(ascii)); 520 DCHECK(IsStringASCII(ascii)) << ascii;
521 return string16(ascii.begin(), ascii.end()); 521 return string16(ascii.begin(), ascii.end());
522 } 522 }
523 523
524 // Latin1 is just the low range of Unicode, so we can copy directly to convert. 524 // Latin1 is just the low range of Unicode, so we can copy directly to convert.
525 bool WideToLatin1(const std::wstring& wide, std::string* latin1) { 525 bool WideToLatin1(const std::wstring& wide, std::string* latin1) {
526 std::string output; 526 std::string output;
527 output.resize(wide.size()); 527 output.resize(wide.size());
528 latin1->clear(); 528 latin1->clear();
529 for (size_t i = 0; i < wide.size(); i++) { 529 for (size_t i = 0; i < wide.size(); i++) {
530 if (wide[i] > 255) 530 if (wide[i] > 255)
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 // Each input byte creates two output hex characters. 1665 // Each input byte creates two output hex characters.
1666 std::string ret(size * 2, '\0'); 1666 std::string ret(size * 2, '\0');
1667 1667
1668 for (size_t i = 0; i < size; ++i) { 1668 for (size_t i = 0; i < size; ++i) {
1669 char b = reinterpret_cast<const char*>(bytes)[i]; 1669 char b = reinterpret_cast<const char*>(bytes)[i];
1670 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf]; 1670 ret[(i * 2)] = kHexChars[(b >> 4) & 0xf];
1671 ret[(i * 2) + 1] = kHexChars[b & 0xf]; 1671 ret[(i * 2) + 1] = kHexChars[b & 0xf];
1672 } 1672 }
1673 return ret; 1673 return ret;
1674 } 1674 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698