Index: third_party/WebKit/Source/wtf/text/UTF8.cpp |
diff --git a/third_party/WebKit/Source/wtf/text/UTF8.cpp b/third_party/WebKit/Source/wtf/text/UTF8.cpp |
index 0beca10497c8e8411d13883305a172c28b264b45..a258db81b99a483309b80078de146aed8053d9c3 100644 |
--- a/third_party/WebKit/Source/wtf/text/UTF8.cpp |
+++ b/third_party/WebKit/Source/wtf/text/UTF8.cpp |
@@ -442,5 +442,23 @@ bool equalLatin1WithUTF8(const LChar* a, const LChar* aEnd, const char* b, const |
return equalWithUTF8Internal(a, aEnd, b, bEnd); |
} |
+bool isUTF8andNotASCII(const char* data, size_t length) |
+{ |
+ // This cast is necessary because U8_NEXT uses int32_ts. |
+ int32_t srcLen = static_cast<int32_t>(length); |
+ int32_t charIndex = 0; |
+ bool isASCIIOnly = true; |
+ |
+ while (charIndex < srcLen) { |
+ int32_t codePoint; |
+ if (static_cast<uint8_t>(data[charIndex]) >= 0x80) |
+ isASCIIOnly = false; |
+ U8_NEXT(data, charIndex, srcLen, codePoint); |
+ if (!U_IS_UNICODE_CHAR(codePoint)) |
+ return false; |
+ } |
+ return !isASCIIOnly; |
+} |
+ |
} // namespace Unicode |
} // namespace WTF |