Skip to content

Commit

Permalink
Make base::IsUnicodeWhitespace('\0') return false.
Browse files Browse the repository at this point in the history
BUG=542759

Review URL: https://codereview.chromium.org/1399253004

Cr-Commit-Position: refs/heads/master@{#353905}
  • Loading branch information
eroman authored and Commit bot committed Oct 13, 2015
1 parent cb4422c commit e61e2b1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
9 changes: 9 additions & 0 deletions base/strings/string_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,15 @@ char HexDigitToInt(wchar_t c) {
return 0;
}

bool IsUnicodeWhitespace(wchar_t c) {
// kWhitespaceWide is a NULL-terminated string
for (const wchar_t* cur = kWhitespaceWide; *cur; ++cur) {
if (*cur == c)
return true;
}
return false;
}

static const char* const kByteStringsUnlocalized[] = {
" B",
" kB",
Expand Down
4 changes: 1 addition & 3 deletions base/strings/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,7 @@ inline bool IsHexDigit(Char c) {
BASE_EXPORT char HexDigitToInt(wchar_t c);

// Returns true if it's a Unicode whitespace character.
inline bool IsUnicodeWhitespace(wchar_t c) {
return wcschr(base::kWhitespaceWide, c) != NULL;
}
BASE_EXPORT bool IsUnicodeWhitespace(wchar_t c);

// Return a byte string in human-readable format with a unit suffix. Not
// appropriate for use in any UI; use of FormatBytes and friends in ui/base is
Expand Down
20 changes: 20 additions & 0 deletions base/strings/string_util_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,26 @@ TEST(StringUtilTest, EqualsCaseInsensitiveASCII) {
EXPECT_FALSE(EqualsCaseInsensitiveASCII("Asdf", "aSDFz"));
}

TEST(StringUtilTest, IsUnicodeWhitespace) {
// NOT unicode white space.
EXPECT_FALSE(IsUnicodeWhitespace(L'\0'));
EXPECT_FALSE(IsUnicodeWhitespace(L'A'));
EXPECT_FALSE(IsUnicodeWhitespace(L'0'));
EXPECT_FALSE(IsUnicodeWhitespace(L'.'));
EXPECT_FALSE(IsUnicodeWhitespace(L';'));
EXPECT_FALSE(IsUnicodeWhitespace(L'\x4100'));

// Actual unicode whitespace.
EXPECT_TRUE(IsUnicodeWhitespace(L' '));
EXPECT_TRUE(IsUnicodeWhitespace(L'\xa0'));
EXPECT_TRUE(IsUnicodeWhitespace(L'\x3000'));
EXPECT_TRUE(IsUnicodeWhitespace(L'\t'));
EXPECT_TRUE(IsUnicodeWhitespace(L'\r'));
EXPECT_TRUE(IsUnicodeWhitespace(L'\v'));
EXPECT_TRUE(IsUnicodeWhitespace(L'\f'));
EXPECT_TRUE(IsUnicodeWhitespace(L'\n'));
}

class WriteIntoTest : public testing::Test {
protected:
static void WritesCorrectly(size_t num_chars) {
Expand Down

0 comments on commit e61e2b1

Please sign in to comment.