diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-14 20:31:49 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-14 20:31:49 +0000 |
commit | 866ba3fc1097334050b59b919e12e11314f2965d (patch) | |
tree | c05394b43a97cd8e34bbefafaf7ad34f03a4e943 /base | |
parent | b7e2b7a2262be4ee720e8c11551fb5a08c8111ee (diff) | |
download | chromium_src-866ba3fc1097334050b59b919e12e11314f2965d.zip chromium_src-866ba3fc1097334050b59b919e12e11314f2965d.tar.gz chromium_src-866ba3fc1097334050b59b919e12e11314f2965d.tar.bz2 |
Re-attempt r28993
Add string16 support for TrimString, TrimWhitespace, and CollapseWhitespace.
Also adds kWhitespaceUTF16.
R=brettw
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/275019
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29012 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r-- | base/string_util.cc | 85 | ||||
-rw-r--r-- | base/string_util.h | 7 |
2 files changed, 64 insertions, 28 deletions
diff --git a/base/string_util.cc b/base/string_util.cc index 480d199..e02aa90 100644 --- a/base/string_util.cc +++ b/base/string_util.cc @@ -344,35 +344,41 @@ const string16& EmptyString16() { return Singleton<EmptyStrings>::get()->s16; } -const wchar_t kWhitespaceWide[] = { - 0x0009, // <control-0009> to <control-000D> - 0x000A, - 0x000B, - 0x000C, - 0x000D, - 0x0020, // Space - 0x0085, // <control-0085> - 0x00A0, // No-Break Space - 0x1680, // Ogham Space Mark - 0x180E, // Mongolian Vowel Separator - 0x2000, // En Quad to Hair Space - 0x2001, - 0x2002, - 0x2003, - 0x2004, - 0x2005, - 0x2006, - 0x2007, - 0x2008, - 0x2009, - 0x200A, - 0x200C, // Zero Width Non-Joiner - 0x2028, // Line Separator - 0x2029, // Paragraph Separator - 0x202F, // Narrow No-Break Space - 0x205F, // Medium Mathematical Space - 0x3000, // Ideographic Space +#define WHITESPACE_UNICODE \ + 0x0009, /* <control-0009> to <control-000D> */ \ + 0x000A, \ + 0x000B, \ + 0x000C, \ + 0x000D, \ + 0x0020, /* Space */ \ + 0x0085, /* <control-0085> */ \ + 0x00A0, /* No-Break Space */ \ + 0x1680, /* Ogham Space Mark */ \ + 0x180E, /* Mongolian Vowel Separator */ \ + 0x2000, /* En Quad to Hair Space */ \ + 0x2001, \ + 0x2002, \ + 0x2003, \ + 0x2004, \ + 0x2005, \ + 0x2006, \ + 0x2007, \ + 0x2008, \ + 0x2009, \ + 0x200A, \ + 0x200C, /* Zero Width Non-Joiner */ \ + 0x2028, /* Line Separator */ \ + 0x2029, /* Paragraph Separator */ \ + 0x202F, /* Narrow No-Break Space */ \ + 0x205F, /* Medium Mathematical Space */ \ + 0x3000, /* Ideographic Space */ \ 0 + +const wchar_t kWhitespaceWide[] = { + WHITESPACE_UNICODE +}; +const char16 kWhitespaceUTF16[] = { + WHITESPACE_UNICODE }; const char kWhitespaceASCII[] = { 0x09, // <control-0009> to <control-000D> @@ -422,6 +428,14 @@ bool TrimString(const std::wstring& input, return TrimStringT(input, trim_chars, TRIM_ALL, output) != TRIM_NONE; } +#if !defined(WCHAR_T_IS_UTF16) +bool TrimString(const string16& input, + const char16 trim_chars[], + string16* output) { + return TrimStringT(input, trim_chars, TRIM_ALL, output) != TRIM_NONE; +} +#endif + bool TrimString(const std::string& input, const char trim_chars[], std::string* output) { @@ -434,6 +448,14 @@ TrimPositions TrimWhitespace(const std::wstring& input, return TrimStringT(input, kWhitespaceWide, positions, output); } +#if !defined(WCHAR_T_IS_UTF16) +TrimPositions TrimWhitespace(const string16& input, + TrimPositions positions, + string16* output) { + return TrimStringT(input, kWhitespaceUTF16, positions, output); +} +#endif + TrimPositions TrimWhitespaceASCII(const std::string& input, TrimPositions positions, std::string* output) { @@ -495,6 +517,13 @@ std::wstring CollapseWhitespace(const std::wstring& text, return CollapseWhitespaceT(text, trim_sequences_with_line_breaks); } +#if !defined(WCHAR_T_IS_UTF16) +string16 CollapseWhitespace(const string16& text, + bool trim_sequences_with_line_breaks) { + return CollapseWhitespaceT(text, trim_sequences_with_line_breaks); +} +#endif + std::string CollapseWhitespaceASCII(const std::string& text, bool trim_sequences_with_line_breaks) { return CollapseWhitespaceT(text, trim_sequences_with_line_breaks); diff --git a/base/string_util.h b/base/string_util.h index 333f5f6..5f7afea 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -120,6 +120,7 @@ const std::wstring& EmptyWString(); const string16& EmptyString16(); extern const wchar_t kWhitespaceWide[]; +extern const char16 kWhitespaceUTF16[]; extern const char kWhitespaceASCII[]; // Removes characters in trim_chars from the beginning and end of input. @@ -127,6 +128,9 @@ extern const char kWhitespaceASCII[]; bool TrimString(const std::wstring& input, const wchar_t trim_chars[], std::wstring* output); +bool TrimString(const string16& input, + const char16 trim_chars[], + string16* output); bool TrimString(const std::string& input, const char trim_chars[], std::string* output); @@ -147,6 +151,9 @@ enum TrimPositions { TrimPositions TrimWhitespace(const std::wstring& input, TrimPositions positions, std::wstring* output); +TrimPositions TrimWhitespace(const string16& input, + TrimPositions positions, + string16* output); TrimPositions TrimWhitespaceASCII(const std::string& input, TrimPositions positions, std::string* output); |