Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Unified Diff: base/strings/string_util_unittest.cc

Issue 543043002: Implement fast path in UTF8ToUTF16 for pure ASCII strings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/strings/string_util.cc ('k') | base/strings/utf_string_conversions.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/strings/string_util_unittest.cc
diff --git a/base/strings/string_util_unittest.cc b/base/strings/string_util_unittest.cc
index 0928c0f9d2237e6339b5489017888093022b9911..16448467901e442c11966d92c3dae421f9bc48c3 100644
--- a/base/strings/string_util_unittest.cc
+++ b/base/strings/string_util_unittest.cc
@@ -386,6 +386,55 @@ TEST(StringUtilTest, IsStringUTF8) {
EXPECT_FALSE(IsStringUTF8("embedded\xc0\x80U+0000"));
}
+TEST(StringUtilTest, IsStringASCII) {
+ static char char_ascii[] =
+ "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
+ static char16 char16_ascii[] = {
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'A',
+ 'B', 'C', 'D', 'E', 'F', '0', '1', '2', '3', '4', '5', '6',
+ '7', '8', '9', '0', 'A', 'B', 'C', 'D', 'E', 'F', 0 };
+
+ // Test a variety of the fragment start positions and lengths in order to make
+ // sure that bit masking in IsStringASCII works correctly.
+ // Also, test that a non-ASCII character will be detected regardless of its
+ // position inside the string.
+ {
+ const size_t string_length = arraysize(char_ascii) - 1;
+ for (size_t offset = 0; offset < 8; ++offset) {
+ for (size_t len = 0, max_len = string_length - offset; len < max_len;
+ ++len) {
+ EXPECT_TRUE(IsStringASCII(StringPiece(char_ascii + offset, len)));
+ for (size_t char_pos = offset; char_pos < len; ++char_pos) {
+ char_ascii[char_pos] |= '\x80';
+ EXPECT_FALSE(IsStringASCII(StringPiece(char_ascii + offset, len)));
+ char_ascii[char_pos] &= ~'\x80';
+ }
+ }
+ }
+ }
+
+ {
+ const size_t string_length = arraysize(char16_ascii) - 1;
+ for (size_t offset = 0; offset < 4; ++offset) {
+ for (size_t len = 0, max_len = string_length - offset; len < max_len;
+ ++len) {
+ EXPECT_TRUE(IsStringASCII(StringPiece16(char16_ascii + offset, len)));
+ for (size_t char_pos = offset; char_pos < len; ++char_pos) {
+ char16_ascii[char_pos] |= 0x80;
+ EXPECT_FALSE(
+ IsStringASCII(StringPiece16(char16_ascii + offset, len)));
+ char16_ascii[char_pos] &= ~0x80;
+ // Also test when the upper half is non-zero.
+ char16_ascii[char_pos] |= 0x100;
+ EXPECT_FALSE(
+ IsStringASCII(StringPiece16(char16_ascii + offset, len)));
+ char16_ascii[char_pos] &= ~0x100;
+ }
+ }
+ }
+ }
+}
+
TEST(StringUtilTest, ConvertASCII) {
static const char* char_cases[] = {
"Google Video",
« no previous file with comments | « base/strings/string_util.cc ('k') | base/strings/utf_string_conversions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698