about summary refs log tree commit diff
path: root/absl/strings
diff options
context:
space:
mode:
authorAbseil Team <absl-team@google.com>2018-02-01T04·34-0800
committerjueminyang <jueminyang@google.com>2018-02-01T15·36-0500
commit0ec11bad6fc18822e851b25344f027491cc85746 (patch)
tree7122b7b3409bd457bc1edb1f1b61cd3a892feeb5 /absl/strings
parent8a401394b8f71da745b3ad6e7c783d7f13ef5428 (diff)
Changes imported from Abseil "staging" branch:
  - 06abebb2bdb201c572da209fc7f781d6bd774d6b Documentation fixes for `absl::optional`. by Abseil Team <absl-team@google.com>
  - 42adc4c4daade2e070dc337e94d8851a1fd4bead  Rolling back the previous change because `__has_warning`... by Xiaoyi Zhang <zhangxy@google.com>
  - 02a42cbaa97d82ee7942bc498538359185d75087 Remove literal UTF8 strings in abseil code to avoid file ... by Jon Cohen <cohenjon@google.com>

GitOrigin-RevId: 06abebb2bdb201c572da209fc7f781d6bd774d6b
Change-Id: I4f4659c2e7ca6fc585b6c089bcf20ca61aced75d
Diffstat (limited to 'absl/strings')
-rw-r--r--absl/strings/str_split_test.cc15
-rw-r--r--absl/strings/string_view_test.cc7
2 files changed, 15 insertions, 7 deletions
diff --git a/absl/strings/str_split_test.cc b/absl/strings/str_split_test.cc
index 500f3cbc3789..b1db1c5647e7 100644
--- a/absl/strings/str_split_test.cc
+++ b/absl/strings/str_split_test.cc
@@ -621,23 +621,28 @@ TEST(Split, StringDelimiter) {
 
 TEST(Split, UTF8) {
   // Tests splitting utf8 strings and utf8 delimiters.
+  std::string utf8_string = "\u03BA\u1F79\u03C3\u03BC\u03B5";
   {
     // A utf8 input std::string with an ascii delimiter.
-    std::vector<absl::string_view> v = absl::StrSplit("a,κόσμε", ',');
-    EXPECT_THAT(v, ElementsAre("a", "κόσμε"));
+    std::string to_split = "a," + utf8_string;
+    std::vector<absl::string_view> v = absl::StrSplit(to_split, ',');
+    EXPECT_THAT(v, ElementsAre("a", utf8_string));
   }
 
   {
     // A utf8 input std::string and a utf8 delimiter.
-    std::vector<absl::string_view> v = absl::StrSplit("a,κόσμε,b", ",κόσμε,");
+    std::string to_split = "a," + utf8_string + ",b";
+    std::string unicode_delimiter = "," + utf8_string + ",";
+    std::vector<absl::string_view> v =
+        absl::StrSplit(to_split, unicode_delimiter);
     EXPECT_THAT(v, ElementsAre("a", "b"));
   }
 
   {
     // A utf8 input std::string and ByAnyChar with ascii chars.
     std::vector<absl::string_view> v =
-        absl::StrSplit("Foo hällo th丞re", absl::ByAnyChar(" \t"));
-    EXPECT_THAT(v, ElementsAre("Foo", "hällo", "th丞re"));
+        absl::StrSplit("Foo h\u00E4llo th\u4E1Ere", absl::ByAnyChar(" \t"));
+    EXPECT_THAT(v, ElementsAre("Foo", "h\u00E4llo", "th\u4E1Ere"));
   }
 }
 
diff --git a/absl/strings/string_view_test.cc b/absl/strings/string_view_test.cc
index df307ac7cfab..3077d240d17b 100644
--- a/absl/strings/string_view_test.cc
+++ b/absl/strings/string_view_test.cc
@@ -684,8 +684,11 @@ TEST(StringViewTest, TruncSubstr) {
 }
 
 TEST(StringViewTest, UTF8) {
-  EXPECT_EQ(strlen("á"), absl::string_view("á á").find_first_of(" "));
-  EXPECT_EQ(strlen("á"), absl::string_view("á á").find_first_of(" \t"));
+  std::string utf8 = "\u00E1";
+  std::string utf8_twice = utf8 + " " + utf8;
+  int utf8_len = strlen(utf8.data());
+  EXPECT_EQ(utf8_len, absl::string_view(utf8_twice).find_first_of(" "));
+  EXPECT_EQ(utf8_len, absl::string_view(utf8_twice).find_first_of(" \t"));
 }
 
 TEST(StringViewTest, FindConformance) {