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

Unified Diff: third_party/WebKit/public/platform/WebString.h

Issue 2629573002: Allow WebString.utf8() to take UTF8ConversionMode (Closed)
Patch Set: comment fix Created 3 years, 11 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/StringUTF8Adaptor.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/public/platform/WebString.h
diff --git a/third_party/WebKit/public/platform/WebString.h b/third_party/WebKit/public/platform/WebString.h
index 5c1c5406f5af30f85631655cc9ba0340752e8d1c..b5e4a896ccd590fefd45461a798cc42a5b7e2fa5 100644
--- a/third_party/WebKit/public/platform/WebString.h
+++ b/third_party/WebKit/public/platform/WebString.h
@@ -66,6 +66,11 @@ namespace blink {
// * webstring.utf16()
// * WebString::toNullableString16(webstring)
//
+// Note that if you need to convert the UTF8 string converted from WebString
+// back to WebString with fromUTF8() you may want to specify Strict
+// UTF8ConversionMode when you call utf8(), as fromUTF8 rejects strings
+// with invalid UTF8 characters.
+//
// Some types like GURL and base::FilePath can directly take either utf-8 or
// utf-16 strings. Use following methods to convert WebString to/from GURL or
// FilePath rather than going through intermediate string types:
@@ -79,6 +84,16 @@ namespace blink {
//
class WebString {
public:
+ enum class UTF8ConversionMode {
+ // Ignores errors for invalid characters.
+ kLenient,
+ // Errors out on invalid characters, returns null string.
+ kStrict,
+ // Replace invalid characters with 0xFFFD.
+ // (This is the same conversion mode as base::UTF16ToUTF8)
+ kStrictReplacingErrorsWithFFFD,
+ };
+
~WebString() { reset(); }
WebString() {}
@@ -104,7 +119,8 @@ class WebString {
bool isEmpty() const { return !length(); }
bool isNull() const { return m_private.isNull(); }
- BLINK_COMMON_EXPORT std::string utf8() const;
+ BLINK_COMMON_EXPORT std::string utf8(
+ UTF8ConversionMode = UTF8ConversionMode::kLenient) const;
BLINK_COMMON_EXPORT static WebString fromUTF8(const char* data,
size_t length);
« no previous file with comments | « third_party/WebKit/Source/wtf/text/StringUTF8Adaptor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698