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

Side by Side Diff: base/string_util_icu.cc

Issue 171012: Use 'icu::' namespace explicitly (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
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 | Annotate | Revision Log
« no previous file with comments | « base/file_util_posix.cc ('k') | base/time_format.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 (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 <string.h> 7 #include <string.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 624
625 utf16->resize(actual_size); 625 utf16->resize(actual_size);
626 return true; 626 return true;
627 } 627 }
628 628
629 // Number formatting ----------------------------------------------------------- 629 // Number formatting -----------------------------------------------------------
630 630
631 namespace { 631 namespace {
632 632
633 struct NumberFormatSingletonTraits 633 struct NumberFormatSingletonTraits
634 : public DefaultSingletonTraits<NumberFormat> { 634 : public DefaultSingletonTraits<icu::NumberFormat> {
635 static NumberFormat* New() { 635 static icu::NumberFormat* New() {
636 UErrorCode status = U_ZERO_ERROR; 636 UErrorCode status = U_ZERO_ERROR;
637 NumberFormat* formatter = NumberFormat::createInstance(status); 637 icu::NumberFormat* formatter = icu::NumberFormat::createInstance(status);
638 DCHECK(U_SUCCESS(status)); 638 DCHECK(U_SUCCESS(status));
639 return formatter; 639 return formatter;
640 } 640 }
641 // There's no ICU call to destroy a NumberFormat object other than 641 // There's no ICU call to destroy a NumberFormat object other than
642 // operator delete, so use the default Delete, which calls operator delete. 642 // operator delete, so use the default Delete, which calls operator delete.
643 // This can cause problems if a different allocator is used by this file than 643 // This can cause problems if a different allocator is used by this file than
644 // by ICU. 644 // by ICU.
645 }; 645 };
646 646
647 } // namespace 647 } // namespace
648 648
649 std::wstring FormatNumber(int64 number) { 649 std::wstring FormatNumber(int64 number) {
650 NumberFormat* number_format = 650 icu::NumberFormat* number_format =
651 Singleton<NumberFormat, NumberFormatSingletonTraits>::get(); 651 Singleton<icu::NumberFormat, NumberFormatSingletonTraits>::get();
652 652
653 if (!number_format) { 653 if (!number_format) {
654 // As a fallback, just return the raw number in a string. 654 // As a fallback, just return the raw number in a string.
655 return StringPrintf(L"%lld", number); 655 return StringPrintf(L"%lld", number);
656 } 656 }
657 UnicodeString ustr; 657 icu::UnicodeString ustr;
658 number_format->format(number, ustr); 658 number_format->format(number, ustr);
659 659
660 #if defined(WCHAR_T_IS_UTF16) 660 #if defined(WCHAR_T_IS_UTF16)
661 return std::wstring(ustr.getBuffer(), 661 return std::wstring(ustr.getBuffer(),
662 static_cast<std::wstring::size_type>(ustr.length())); 662 static_cast<std::wstring::size_type>(ustr.length()));
663 #elif defined(WCHAR_T_IS_UTF32) 663 #elif defined(WCHAR_T_IS_UTF32)
664 wchar_t buffer[64]; // A int64 is less than 20 chars long, so 64 chars 664 wchar_t buffer[64]; // A int64 is less than 20 chars long, so 64 chars
665 // leaves plenty of room for formating stuff. 665 // leaves plenty of room for formating stuff.
666 int length = 0; 666 int length = 0;
667 UErrorCode error = U_ZERO_ERROR; 667 UErrorCode error = U_ZERO_ERROR;
(...skipping 16 matching lines...) Expand all
684 // This implementation is not so fast since it converts the text encoding 684 // This implementation is not so fast since it converts the text encoding
685 // twice. Please feel free to file a bug if this function hurts the 685 // twice. Please feel free to file a bug if this function hurts the
686 // performance of Chrome. 686 // performance of Chrome.
687 DCHECK(IsStringUTF8(input)); 687 DCHECK(IsStringUTF8(input));
688 std::wstring input_wide = UTF8ToWide(input); 688 std::wstring input_wide = UTF8ToWide(input);
689 std::wstring output_wide; 689 std::wstring output_wide;
690 TrimPositions result = TrimWhitespace(input_wide, positions, &output_wide); 690 TrimPositions result = TrimWhitespace(input_wide, positions, &output_wide);
691 *output = WideToUTF8(output_wide); 691 *output = WideToUTF8(output_wide);
692 return result; 692 return result;
693 } 693 }
OLDNEW
« no previous file with comments | « base/file_util_posix.cc ('k') | base/time_format.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698