diff options
author | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-02 05:29:53 +0000 |
---|---|---|
committer | brettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-02 05:29:53 +0000 |
commit | 8790210c68de5ab29e54a46f761a7a8d60430334 (patch) | |
tree | 159098319252d715c174230adbeb88338a6f67e4 /base/strings | |
parent | 05fd507a71a552edc3290adc35c45dfdc13d251a (diff) | |
download | chromium_src-8790210c68de5ab29e54a46f761a7a8d60430334.zip chromium_src-8790210c68de5ab29e54a46f761a7a8d60430334.tar.gz chromium_src-8790210c68de5ab29e54a46f761a7a8d60430334.tar.bz2 |
Move EmptyString, kWhitespace and the BOM to base.
This moves EmptyString*, kWhitespace*, and the UTF 8 Byte Order Marker to the base:: namespace.
Many of them just got changed to a default-constructed string when a reference was not required.
I qualified some string16s with base:: when I was changing adjacent code. I need to do another pass to finish these up.
BUG=
TBR=sky@chromium.org
Review URL: https://codereview.chromium.org/89243003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238032 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/strings')
-rw-r--r-- | base/strings/string_util.cc | 17 | ||||
-rw-r--r-- | base/strings/string_util.h | 41 | ||||
-rw-r--r-- | base/strings/string_util_constants.cc | 4 |
3 files changed, 36 insertions, 26 deletions
diff --git a/base/strings/string_util.cc b/base/strings/string_util.cc index becc60f..4fa3f3f 100644 --- a/base/strings/string_util.cc +++ b/base/strings/string_util.cc @@ -100,9 +100,6 @@ bool IsWprintfFormatPortable(const wchar_t* format) { return true; } -} // namespace base - - const std::string& EmptyString() { return EmptyStrings::GetInstance()->s; } @@ -115,6 +112,8 @@ const string16& EmptyString16() { return EmptyStrings::GetInstance()->s16; } +} // namespace base + template<typename STR> bool ReplaceCharsT(const STR& input, const typename STR::value_type replace_chars[], @@ -241,16 +240,16 @@ void TruncateUTF8ToByteSize(const std::string& input, output->clear(); } -TrimPositions TrimWhitespace(const string16& input, +TrimPositions TrimWhitespace(const base::string16& input, TrimPositions positions, - string16* output) { - return TrimStringT(input, kWhitespaceUTF16, positions, output); + base::string16* output) { + return TrimStringT(input, base::kWhitespaceUTF16, positions, output); } TrimPositions TrimWhitespaceASCII(const std::string& input, TrimPositions positions, std::string* output) { - return TrimStringT(input, kWhitespaceASCII, positions, output); + return TrimStringT(input, base::kWhitespaceASCII, positions, output); } // This function is only for backward-compatibility. @@ -321,8 +320,8 @@ bool ContainsOnlyWhitespaceASCII(const std::string& str) { return true; } -bool ContainsOnlyWhitespace(const string16& str) { - return str.find_first_not_of(kWhitespaceUTF16) == string16::npos; +bool ContainsOnlyWhitespace(const base::string16& str) { + return str.find_first_not_of(base::kWhitespaceUTF16) == string16::npos; } template<typename STR> diff --git a/base/strings/string_util.h b/base/strings/string_util.h index 2b6316b..a6ee815 100644 --- a/base/strings/string_util.h +++ b/base/strings/string_util.h @@ -123,34 +123,41 @@ template<typename Char> struct CaseInsensitiveCompareASCII { } }; -} // namespace base - -#if defined(OS_WIN) -#include "base/strings/string_util_win.h" -#elif defined(OS_POSIX) -#include "base/strings/string_util_posix.h" -#else -#error Define string operations appropriately for your platform -#endif - // These threadsafe functions return references to globally unique empty // strings. // -// DO NOT USE THESE AS A GENERAL-PURPOSE SUBSTITUTE FOR DEFAULT CONSTRUCTORS. -// There is only one case where you should use these: functions which need to -// return a string by reference (e.g. as a class member accessor), and don't -// have an empty string to use (e.g. in an error case). These should not be -// used as initializers, function arguments, or return values for functions -// which return by value or outparam. +// It is likely faster to construct a new empty string object (just a few +// instructions to set the length to 0) than to get the empty string singleton +// returned by these functions (which requires threadsafe singleton access). +// +// Therefore, DO NOT USE THESE AS A GENERAL-PURPOSE SUBSTITUTE FOR DEFAULT +// CONSTRUCTORS. There is only one case where you should use these: functions +// which need to return a string by reference (e.g. as a class member +// accessor), and don't have an empty string to use (e.g. in an error case). +// These should not be used as initializers, function arguments, or return +// values for functions which return by value or outparam. BASE_EXPORT const std::string& EmptyString(); BASE_EXPORT const string16& EmptyString16(); +// Contains the set of characters representing whitespace in the corresponding +// encoding. Null-terminated. BASE_EXPORT extern const wchar_t kWhitespaceWide[]; BASE_EXPORT extern const char16 kWhitespaceUTF16[]; BASE_EXPORT extern const char kWhitespaceASCII[]; +// Null-terminated string representing the UTF-8 byte order mark. BASE_EXPORT extern const char kUtf8ByteOrderMark[]; +} // namespace base + +#if defined(OS_WIN) +#include "base/strings/string_util_win.h" +#elif defined(OS_POSIX) +#include "base/strings/string_util_posix.h" +#else +#error Define string operations appropriately for your platform +#endif + // Removes characters in |remove_chars| from anywhere in |input|. Returns true // if any characters were removed. |remove_chars| must be null-terminated. // NOTE: Safe to use the same variable for both |input| and |output|. @@ -370,7 +377,7 @@ inline Char HexDigitToInt(Char c) { // Returns true if it's a whitespace character. inline bool IsWhitespace(wchar_t c) { - return wcschr(kWhitespaceWide, c) != NULL; + return wcschr(base::kWhitespaceWide, c) != NULL; } // Return a byte string in human-readable format with a unit suffix. Not diff --git a/base/strings/string_util_constants.cc b/base/strings/string_util_constants.cc index d92e40c..2a28a2b 100644 --- a/base/strings/string_util_constants.cc +++ b/base/strings/string_util_constants.cc @@ -4,6 +4,8 @@ #include "base/strings/string_util.h" +namespace base { + #define WHITESPACE_UNICODE \ 0x0009, /* <control-0009> to <control-000D> */ \ 0x000A, \ @@ -53,3 +55,5 @@ const char kWhitespaceASCII[] = { }; const char kUtf8ByteOrderMark[] = "\xEF\xBB\xBF"; + +} // namespace base |