diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/string_util.cc | 18 | ||||
-rw-r--r-- | base/string_util.h | 1 |
2 files changed, 17 insertions, 2 deletions
diff --git a/base/string_util.cc b/base/string_util.cc index a13f79f..8f9bcf9 100644 --- a/base/string_util.cc +++ b/base/string_util.cc @@ -27,6 +27,16 @@ namespace { +// Force the singleton used by Empty[W]String[16] to be a unique type. This +// prevents other code that might accidentally use Singleton<string> from +// getting our internal one. +struct EmptyStrings { + EmptyStrings() {} + const std::string s; + const std::wstring ws; + const string16 s16; +}; + // Hack to convert any char-like type to its unsigned counterpart. // For example, it will convert char, signed char and unsigned char to unsigned // char. @@ -323,11 +333,15 @@ bool IsWprintfFormatPortable(const wchar_t* format) { const std::string& EmptyString() { - return *Singleton<std::string>::get(); + return Singleton<EmptyStrings>::get()->s; } const std::wstring& EmptyWString() { - return *Singleton<std::wstring>::get(); + return Singleton<EmptyStrings>::get()->ws; +} + +const string16& EmptyString16() { + return Singleton<EmptyStrings>::get()->s16; } const wchar_t kWhitespaceWide[] = { diff --git a/base/string_util.h b/base/string_util.h index 1247cd5..3f905fe 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -112,6 +112,7 @@ bool IsWprintfFormatPortable(const wchar_t* format); // These functions are threadsafe. const std::string& EmptyString(); const std::wstring& EmptyWString(); +const string16& EmptyString16(); extern const wchar_t kWhitespaceWide[]; extern const char kWhitespaceASCII[]; |