| Index: third_party/WebKit/Source/platform/inspector_protocol/Parser.cpp
|
| diff --git a/third_party/WebKit/Source/platform/inspector_protocol/Parser.cpp b/third_party/WebKit/Source/platform/inspector_protocol/Parser.cpp
|
| index 349525587b1734d109d5004cc02a1981dbfa59d0..6e79ed2b4136634ca7f6ce25972b707b93541b85 100644
|
| --- a/third_party/WebKit/Source/platform/inspector_protocol/Parser.cpp
|
| +++ b/third_party/WebKit/Source/platform/inspector_protocol/Parser.cpp
|
| @@ -33,8 +33,7 @@ const char* const nullString = "null";
|
| const char* const trueString = "true";
|
| const char* const falseString = "false";
|
|
|
| -template<typename CharType>
|
| -bool parseConstToken(const CharType* start, const CharType* end, const CharType** tokenEnd, const char* token)
|
| +bool parseConstToken(const UChar* start, const UChar* end, const UChar** tokenEnd, const char* token)
|
| {
|
| while (start < end && *token != '\0' && *start++ == *token++) { }
|
| if (*token != '\0')
|
| @@ -43,8 +42,7 @@ bool parseConstToken(const CharType* start, const CharType* end, const CharType*
|
| return true;
|
| }
|
|
|
| -template<typename CharType>
|
| -bool readInt(const CharType* start, const CharType* end, const CharType** tokenEnd, bool canHaveLeadingZeros)
|
| +bool readInt(const UChar* start, const UChar* end, const UChar** tokenEnd, bool canHaveLeadingZeros)
|
| {
|
| if (start == end)
|
| return false;
|
| @@ -62,14 +60,13 @@ bool readInt(const CharType* start, const CharType* end, const CharType** tokenE
|
| return true;
|
| }
|
|
|
| -template<typename CharType>
|
| -bool parseNumberToken(const CharType* start, const CharType* end, const CharType** tokenEnd)
|
| +bool parseNumberToken(const UChar* start, const UChar* end, const UChar** tokenEnd)
|
| {
|
| // We just grab the number here. We validate the size in DecodeNumber.
|
| // According to RFC4627, a valid number is: [minus] int [frac] [exp]
|
| if (start == end)
|
| return false;
|
| - CharType c = *start;
|
| + UChar c = *start;
|
| if ('-' == c)
|
| ++start;
|
|
|
| @@ -112,13 +109,12 @@ bool parseNumberToken(const CharType* start, const CharType* end, const CharType
|
| return true;
|
| }
|
|
|
| -template<typename CharType>
|
| -bool readHexDigits(const CharType* start, const CharType* end, const CharType** tokenEnd, int digits)
|
| +bool readHexDigits(const UChar* start, const UChar* end, const UChar** tokenEnd, int digits)
|
| {
|
| if (end - start < digits)
|
| return false;
|
| for (int i = 0; i < digits; ++i) {
|
| - CharType c = *start++;
|
| + UChar c = *start++;
|
| if (!(('0' <= c && c <= '9') || ('a' <= c && c <= 'f') || ('A' <= c && c <= 'F')))
|
| return false;
|
| }
|
| @@ -126,11 +122,10 @@ bool readHexDigits(const CharType* start, const CharType* end, const CharType**
|
| return true;
|
| }
|
|
|
| -template<typename CharType>
|
| -bool parseStringToken(const CharType* start, const CharType* end, const CharType** tokenEnd)
|
| +bool parseStringToken(const UChar* start, const UChar* end, const UChar** tokenEnd)
|
| {
|
| while (start < end) {
|
| - CharType c = *start++;
|
| + UChar c = *start++;
|
| if ('\\' == c) {
|
| c = *start++;
|
| // Make sure the escaped char is valid.
|
| @@ -164,8 +159,7 @@ bool parseStringToken(const CharType* start, const CharType* end, const CharType
|
| return false;
|
| }
|
|
|
| -template<typename CharType>
|
| -bool skipComment(const CharType* start, const CharType* end, const CharType** commentEnd)
|
| +bool skipComment(const UChar* start, const UChar* end, const UChar** commentEnd)
|
| {
|
| if (start == end)
|
| return false;
|
| @@ -188,7 +182,7 @@ bool skipComment(const CharType* start, const CharType* end, const CharType** co
|
| }
|
|
|
| if (*start == '*') {
|
| - CharType previous = '\0';
|
| + UChar previous = '\0';
|
| // Block comment, read until end marker.
|
| for (++start; start < end; previous = *start++) {
|
| if (previous == '*' && *start == '/') {
|
| @@ -203,14 +197,13 @@ bool skipComment(const CharType* start, const CharType* end, const CharType** co
|
| return false;
|
| }
|
|
|
| -template<typename CharType>
|
| -void skipWhitespaceAndComments(const CharType* start, const CharType* end, const CharType** whitespaceEnd)
|
| +void skipWhitespaceAndComments(const UChar* start, const UChar* end, const UChar** whitespaceEnd)
|
| {
|
| while (start < end) {
|
| if (isSpaceOrNewline(*start)) {
|
| ++start;
|
| } else if (*start == '/') {
|
| - const CharType* commentEnd;
|
| + const UChar* commentEnd;
|
| if (!skipComment(start, end, &commentEnd))
|
| break;
|
| start = commentEnd;
|
| @@ -221,8 +214,7 @@ void skipWhitespaceAndComments(const CharType* start, const CharType* end, const
|
| *whitespaceEnd = start;
|
| }
|
|
|
| -template<typename CharType>
|
| -Token parseToken(const CharType* start, const CharType* end, const CharType** tokenStart, const CharType** tokenEnd)
|
| +Token parseToken(const UChar* start, const UChar* end, const UChar** tokenStart, const UChar** tokenEnd)
|
| {
|
| skipWhitespaceAndComments(start, end, tokenStart);
|
| start = *tokenStart;
|
| @@ -283,8 +275,7 @@ Token parseToken(const CharType* start, const CharType* end, const CharType** to
|
| return InvalidToken;
|
| }
|
|
|
| -template<typename CharType>
|
| -inline int hexToInt(CharType c)
|
| +inline int hexToInt(UChar c)
|
| {
|
| if ('0' <= c && c <= '9')
|
| return c - '0';
|
| @@ -296,52 +287,7 @@ inline int hexToInt(CharType c)
|
| return 0;
|
| }
|
|
|
| -template<typename CharType>
|
| -bool decodeUTF8(const CharType* start, const CharType* end, const CharType** utf8charEnd, String16Builder* output)
|
| -{
|
| - UChar utf16[4] = {0};
|
| - char utf8[6] = {0};
|
| - size_t utf8count = 0;
|
| -
|
| - while (start < end) {
|
| - if (start + 1 >= end || *start != '\\' || *(start + 1) != 'x')
|
| - return false;
|
| - start += 2;
|
| -
|
| - // Accumulate one more utf8 character and try converting to utf16.
|
| - if (start + 1 >= end)
|
| - return false;
|
| - utf8[utf8count++] = (hexToInt(*start) << 4) + hexToInt(*(start + 1));
|
| - start += 2;
|
| -
|
| - const char* utf8start = utf8;
|
| - UChar* utf16start = utf16;
|
| - String16::ConversionResult conversionResult = String16::convertUTF8ToUTF16(&utf8start, utf8start + utf8count, &utf16start, utf16start + 4, nullptr, true);
|
| -
|
| - if (conversionResult == String16::sourceIllegal)
|
| - return false;
|
| -
|
| - if (conversionResult == String16::conversionOK) {
|
| - // Not all utf8 characters were consumed - failed parsing.
|
| - if (utf8start != utf8 + utf8count)
|
| - return false;
|
| -
|
| - size_t utf16length = utf16start - utf16;
|
| - output->append(utf16, utf16length);
|
| - *utf8charEnd = start;
|
| - return true;
|
| - }
|
| -
|
| - // Keep accumulating utf8 characters up to buffer length (6 should be enough).
|
| - if (utf8count >= 6)
|
| - return false;
|
| - }
|
| -
|
| - return false;
|
| -}
|
| -
|
| -template<typename CharType>
|
| -bool decodeString(const CharType* start, const CharType* end, String16Builder* output)
|
| +bool decodeString(const UChar* start, const UChar* end, String16Builder* output)
|
| {
|
| while (start < end) {
|
| UChar c = *start++;
|
| @@ -352,10 +298,8 @@ bool decodeString(const CharType* start, const CharType* end, String16Builder* o
|
| c = *start++;
|
|
|
| if (c == 'x') {
|
| - // Rewind "\x".
|
| - if (!decodeUTF8(start - 2, end, &start, output))
|
| - return false;
|
| - continue;
|
| + // \x is not supported.
|
| + return false;
|
| }
|
|
|
| switch (c) {
|
| @@ -396,8 +340,7 @@ bool decodeString(const CharType* start, const CharType* end, String16Builder* o
|
| return true;
|
| }
|
|
|
| -template<typename CharType>
|
| -bool decodeString(const CharType* start, const CharType* end, String16* output)
|
| +bool decodeString(const UChar* start, const UChar* end, String16* output)
|
| {
|
| if (start == end) {
|
| *output = "";
|
| @@ -410,21 +353,17 @@ bool decodeString(const CharType* start, const CharType* end, String16* output)
|
| if (!decodeString(start, end, &buffer))
|
| return false;
|
| *output = buffer.toString();
|
| - // Validate constructed utf16 string.
|
| - if (!output->validateUTF8())
|
| - return false;
|
| return true;
|
| }
|
|
|
| -template<typename CharType>
|
| -PassOwnPtr<Value> buildValue(const CharType* start, const CharType* end, const CharType** valueTokenEnd, int depth)
|
| +PassOwnPtr<Value> buildValue(const UChar* start, const UChar* end, const UChar** valueTokenEnd, int depth)
|
| {
|
| if (depth > stackLimit)
|
| return nullptr;
|
|
|
| OwnPtr<Value> result;
|
| - const CharType* tokenStart;
|
| - const CharType* tokenEnd;
|
| + const UChar* tokenStart;
|
| + const UChar* tokenEnd;
|
| Token token = parseToken(start, end, &tokenStart, &tokenEnd);
|
| switch (token) {
|
| case InvalidToken:
|
| @@ -533,11 +472,10 @@ PassOwnPtr<Value> buildValue(const CharType* start, const CharType* end, const C
|
| return result.release();
|
| }
|
|
|
| -template<typename CharType>
|
| -PassOwnPtr<Value> parseJSONInternal(const CharType* start, unsigned length)
|
| +PassOwnPtr<Value> parseJSONInternal(const UChar* start, unsigned length)
|
| {
|
| - const CharType* end = start + length;
|
| - const CharType *tokenEnd;
|
| + const UChar* end = start + length;
|
| + const UChar *tokenEnd;
|
| OwnPtr<Value> value = buildValue(start, end, &tokenEnd, 0);
|
| if (!value || tokenEnd != end)
|
| return nullptr;
|
| @@ -550,8 +488,6 @@ PassOwnPtr<Value> parseJSON(const String16& json)
|
| {
|
| if (json.isEmpty())
|
| return nullptr;
|
| - if (json.is8Bit())
|
| - return parseJSONInternal(json.characters8(), json.length());
|
| return parseJSONInternal(json.characters16(), json.length());
|
| }
|
|
|
|
|