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

Unified Diff: third_party/WebKit/Source/wtf/text/WTFStringTest.cpp

Issue 1382583002: Add toStdString methods to CString and WTF::String (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Back to String::toUTF8StdString Created 5 years, 2 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 | « third_party/WebKit/Source/wtf/text/WTFString.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/wtf/text/WTFStringTest.cpp
diff --git a/third_party/WebKit/Source/wtf/text/WTFStringTest.cpp b/third_party/WebKit/Source/wtf/text/WTFStringTest.cpp
index 66cf6370575e91a79756585de2b5ad831776f677..efa099da6ac83fe9db89543fb17a8abff0199067 100644
--- a/third_party/WebKit/Source/wtf/text/WTFStringTest.cpp
+++ b/third_party/WebKit/Source/wtf/text/WTFStringTest.cpp
@@ -347,4 +347,23 @@ TEST(StringTest, Lower)
EXPECT_STREQ("link", String::fromUTF8("LIN\xE2\x84\xAA").lower().utf8().data());
}
+TEST(StringTest, ToStdString)
+{
+ // Empty string case.
+ EXPECT_TRUE(String("").toUTF8StdString().empty());
+ EXPECT_EQ(std::string(), String("").toUTF8StdString());
+
+ // ASCII string case.
+ char kAsciiChars[] = "1";
+ EXPECT_EQ(std::string(kAsciiChars), String(kAsciiChars).toUTF8StdString());
+
+ // UTF-8 string case.
+ char kUTF8Chars[] = "r\xC3\xA9sum\xC3\xA9";
+ EXPECT_EQ(std::string(kUTF8Chars), String::fromUTF8(kUTF8Chars).toUTF8StdString());
+
+ // UTF-16 -> UTF-8 string case.
+ UChar kUTF16Chars[] = { 0x20AC, 0xD801, 0 };
+ EXPECT_EQ(std::string("\xE2\x82\xAC\xED\xA0\x81"), String(kUTF16Chars).toUTF8StdString());
+}
+
} // namespace WTF
« no previous file with comments | « third_party/WebKit/Source/wtf/text/WTFString.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698