summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/SConscript2
-rw-r--r--base/base.xcodeproj/project.pbxproj6
-rw-r--r--base/build/base.vcproj4
-rw-r--r--base/string_util_icu.cc25
-rw-r--r--base/string_util_posix.cc66
-rw-r--r--base/string_util_win.cc55
6 files changed, 20 insertions, 138 deletions
diff --git a/base/SConscript b/base/SConscript
index 3b8a409..c38d1fb 100644
--- a/base/SConscript
+++ b/base/SConscript
@@ -128,7 +128,6 @@ if env['PLATFORM'] == 'win32':
'iat_patch.cc',
'lock_impl_win.cc',
'shared_memory_win.cc',
- 'string_util_win.cc',
'sys_string_conversions_win.cc',
'thread_local_storage_win.cc',
'time_win.cc',
@@ -162,7 +161,6 @@ if env['PLATFORM'] == 'posix':
input_files.extend([
'atomicops_internals_x86_gcc.cc',
'file_util_linux.cc',
- 'string_util_posix.cc',
'sys_string_conversions_linux.cc',
])
diff --git a/base/base.xcodeproj/project.pbxproj b/base/base.xcodeproj/project.pbxproj
index 9e45a066..2614a72 100644
--- a/base/base.xcodeproj/project.pbxproj
+++ b/base/base.xcodeproj/project.pbxproj
@@ -128,8 +128,6 @@
A5A0284F0E4CFD7E00498DA9 /* file_util_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = A5A0268D0E4A2BDC00498DA9 /* file_util_posix.cc */; };
A5A028520E4CFDE300498DA9 /* path_service_unittest.cc in Sources */ = {isa = PBXBuildFile; fileRef = E4562AD60E27E27E005E4685 /* path_service_unittest.cc */; };
A5A0286B0E4CFFC700498DA9 /* base_paths_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABF4B98E0DC2BA6900A6E319 /* base_paths_mac.mm */; };
- AB5C95790E525A6400F5B56D /* string_util_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB5C95770E525A6400F5B56D /* string_util_posix.cc */; };
- ABCFB4E70E525B5C008A8C07 /* string_util_posix.cc in Sources */ = {isa = PBXBuildFile; fileRef = AB5C95770E525A6400F5B56D /* string_util_posix.cc */; };
ABF4B98F0DC2BA6900A6E319 /* base_paths_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABF4B98E0DC2BA6900A6E319 /* base_paths_mac.mm */; };
ABF4B99E0DC2BB6000A6E319 /* clipboard_mac.mm in Sources */ = {isa = PBXBuildFile; fileRef = ABF4B99D0DC2BB6000A6E319 /* clipboard_mac.mm */; };
ABF4B9A70DC2BBAE00A6E319 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 829E31330DBFDB6F00819EBF /* CoreGraphics.framework */; };
@@ -527,7 +525,6 @@
A5A0270A0E4A630D00498DA9 /* file_util_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = file_util_mac.mm; sourceTree = "<group>"; };
A5A0276B0E4BA33700498DA9 /* build_config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = build_config.h; path = ../build/build_config.h; sourceTree = SOURCE_ROOT; };
A5A0282D0E4CFA8500498DA9 /* file_util_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = file_util_unittest.cc; sourceTree = "<group>"; };
- AB5C95770E525A6400F5B56D /* string_util_posix.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = string_util_posix.cc; sourceTree = "<group>"; };
ABF4B98E0DC2BA6900A6E319 /* base_paths_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = base_paths_mac.mm; sourceTree = "<group>"; };
ABF4B99D0DC2BB6000A6E319 /* clipboard_mac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = clipboard_mac.mm; sourceTree = "<group>"; };
ABF4B9B40DC2BC9F00A6E319 /* path_service.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = path_service.cc; sourceTree = "<group>"; };
@@ -756,7 +753,6 @@
8254037C0D92D2CF0006B936 /* string_util.cc */,
8254037D0D92D2CF0006B936 /* string_util.h */,
820EB4F90E3A6178009668FC /* string_util_icu.cc */,
- AB5C95770E525A6400F5B56D /* string_util_posix.cc */,
7BAF50A90E50BACB00CA8A07 /* string_util_posix.h */,
7BAF50B10E50BAE700CA8A07 /* string_util_unittest.cc */,
821B91680DAABD7F00F350D7 /* string16.h */,
@@ -1230,7 +1226,6 @@
7B4C5F4A0E4B6BF900679E8F /* sys_string_conversions_mac.cc in Sources */,
7BAF501C0E50B84200CA8A07 /* base_paths.cc in Sources */,
7BAF50760E50B8F100CA8A07 /* file_version_info_mac.mm in Sources */,
- AB5C95790E525A6400F5B56D /* string_util_posix.cc in Sources */,
7B78CE250E5314A000609465 /* debug_util.cc in Sources */,
7B78CE120E53131800609465 /* debug_util_posix.cc in Sources */,
);
@@ -1309,7 +1304,6 @@
E4AFA4C50E50DEF500201347 /* string_piece.cc in Sources */,
E4AFA4E10E50E6BC00201347 /* word_iterator_unittest.cc in Sources */,
E4AFA4E20E50E6BC00201347 /* word_iterator.cc in Sources */,
- ABCFB4E70E525B5C008A8C07 /* string_util_posix.cc in Sources */,
7B78CE260E5314A100609465 /* debug_util.cc in Sources */,
7B78CE110E53131800609465 /* debug_util_posix.cc in Sources */,
);
diff --git a/base/build/base.vcproj b/base/build/base.vcproj
index 07b09dd..35b9684 100644
--- a/base/build/base.vcproj
+++ b/base/build/base.vcproj
@@ -650,10 +650,6 @@
>
</File>
<File
- RelativePath="..\string_util_win.cc"
- >
- </File>
- <File
RelativePath="..\string_util_win.h"
>
</File>
diff --git a/base/string_util_icu.cc b/base/string_util_icu.cc
index fca020b..5774677 100644
--- a/base/string_util_icu.cc
+++ b/base/string_util_icu.cc
@@ -423,13 +423,28 @@ bool CodepageToWide(const std::string& encoded,
// Number formatting -----------------------------------------------------------
-// TODO: http://b/id=1092584 Come up with a portable pthread_once, and use
-// that to keep a singleton instead of putting it in the platform-dependent
-// file.
-NumberFormat* NumberFormatSingleton();
+namespace {
+
+struct NumberFormatSingletonTraits
+ : public DefaultSingletonTraits<NumberFormat> {
+ static NumberFormat* New() {
+ UErrorCode status = U_ZERO_ERROR;
+ NumberFormat* formatter = NumberFormat::createInstance(status);
+ DCHECK(U_SUCCESS(status));
+ return formatter;
+ }
+ // There's no ICU call to destroy a NumberFormat object other than
+ // operator delete, so use the default Delete, which calls operator delete.
+ // This can cause problems if a different allocator is used by this file than
+ // by ICU.
+};
+
+} // namespace
std::wstring FormatNumber(int64 number) {
- NumberFormat* number_format = NumberFormatSingleton();
+ NumberFormat* number_format =
+ Singleton<NumberFormat, NumberFormatSingletonTraits>::get();
+
if (!number_format) {
// As a fallback, just return the raw number in a string.
return StringPrintf(L"%lld", number);
diff --git a/base/string_util_posix.cc b/base/string_util_posix.cc
deleted file mode 100644
index 320764f..0000000
--- a/base/string_util_posix.cc
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2008, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "base/string_util.h"
-
-#include <pthread.h>
-#include <string>
-#include <vector>
-#include "base/logging.h"
-#include "unicode/numfmt.h"
-
-static NumberFormat* number_format_singleton = NULL;
-
-static void DoInitializeStatics() {
- UErrorCode status = U_ZERO_ERROR;
- number_format_singleton = NumberFormat::createInstance(status);
- DCHECK(U_SUCCESS(status));
-}
-
-static void InitializeStatics() {
- static pthread_once_t pthread_once_initialized = PTHREAD_ONCE_INIT;
- pthread_once(&pthread_once_initialized, DoInitializeStatics);
-}
-
-// Technically, the native multibyte encoding would be the encoding returned
-// by CFStringGetSystemEncoding or GetApplicationTextEncoding, but I can't
-// imagine anyone needing or using that from these APIs, so just treat UTF-8
-// as though it were the native multibyte encoding.
-std::string WideToNativeMB(const std::wstring& wide) {
- return WideToUTF8(wide);
-}
-
-std::wstring NativeMBToWide(const std::string& native_mb) {
- return UTF8ToWide(native_mb);
-}
-
-NumberFormat* NumberFormatSingleton() {
- InitializeStatics();
- return number_format_singleton;
-}
diff --git a/base/string_util_win.cc b/base/string_util_win.cc
deleted file mode 100644
index 7592142..0000000
--- a/base/string_util_win.cc
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright 2008, Google Inc.
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above
-// copyright notice, this list of conditions and the following disclaimer
-// in the documentation and/or other materials provided with the
-// distribution.
-// * Neither the name of Google Inc. nor the names of its
-// contributors may be used to endorse or promote products derived from
-// this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#include "base/string_util.h"
-
-#include <windows.h>
-#include <string>
-#include "unicode/numfmt.h"
-#include "base/logging.h"
-
-NumberFormat* NumberFormatSingleton() {
- static NumberFormat* number_format = NULL;
- if (!number_format) {
- // Make sure we are thread-safe.
- UErrorCode status = U_ZERO_ERROR;
- NumberFormat* new_number_format = NumberFormat::createInstance(status);
- if (U_FAILURE(status)) {
- NOTREACHED();
- }
- if (InterlockedCompareExchangePointer(
- reinterpret_cast<PVOID*>(&number_format), new_number_format, NULL)) {
- // The old value was non-NULL, so no replacement was done. Another
- // thread did the initialization out from under us.
- if (new_number_format)
- delete new_number_format;
- }
- }
- return number_format;
-}