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

Unified Diff: third_party/WebKit/Source/platform/exported/WebString.cpp

Issue 2469353003: Skip base::string16 if not necessary for WebString <-> ASCII conversion (Closed)
Patch Set: minor fix Created 4 years, 1 month 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 | « media/blink/webencryptedmediaclient_impl.cc ('k') | third_party/WebKit/public/platform/WebString.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/exported/WebString.cpp
diff --git a/third_party/WebKit/Source/platform/exported/WebString.cpp b/third_party/WebKit/Source/platform/exported/WebString.cpp
index 2ad8fa96244c93585fd797059fa56f6723b6a1a5..8e1c81c3d8a1f084d2e545c4ef50af47de77a96e 100644
--- a/third_party/WebKit/Source/platform/exported/WebString.cpp
+++ b/third_party/WebKit/Source/platform/exported/WebString.cpp
@@ -30,6 +30,8 @@
#include "public/platform/WebString.h"
+#include "base/strings/string_util.h"
+#include "wtf/text/ASCIIFastPath.h"
#include "wtf/text/AtomicString.h"
#include "wtf/text/CString.h"
#include "wtf/text/StringUTF8Adaptor.h"
@@ -97,6 +99,30 @@ WebString WebString::fromLatin1(const WebLChar* data, size_t length) {
return String(data, length);
}
+std::string WebString::ascii() const {
+ DCHECK(containsOnlyASCII());
+
+ if (isEmpty())
+ return std::string();
+
+ if (m_private->is8Bit()) {
+ return std::string(reinterpret_cast<const char*>(m_private->characters8()),
+ m_private->length());
+ }
+
+ return std::string(m_private->characters16(),
+ m_private->characters16() + m_private->length());
+}
+
+bool WebString::containsOnlyASCII() const {
+ return String(m_private.get()).containsOnlyASCII();
+}
+
+WebString WebString::fromASCII(const std::string& s) {
+ DCHECK(base::IsStringASCII(s));
+ return fromLatin1(s);
+}
+
bool WebString::equals(const WebString& s) const {
return equal(m_private.get(), s.m_private.get());
}
« no previous file with comments | « media/blink/webencryptedmediaclient_impl.cc ('k') | third_party/WebKit/public/platform/WebString.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698