| Index: third_party/WebKit/Source/platform/inspector_protocol/Parser_cpp.template
|
| diff --git a/third_party/WebKit/Source/platform/inspector_protocol/Parser_cpp.template b/third_party/WebKit/Source/platform/inspector_protocol/Parser_cpp.template
|
| index 34d8ff0720d046e736dd7a0ea2446a8ec80f27f7..d4e3bd55a26e4eed1aee61d5d4721160f69f0b11 100644
|
| --- a/third_party/WebKit/Source/platform/inspector_protocol/Parser_cpp.template
|
| +++ b/third_party/WebKit/Source/platform/inspector_protocol/Parser_cpp.template
|
| @@ -2,8 +2,9 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -namespace blink {
|
| -namespace protocol {
|
| +{% for namespace in config.protocol.namespace %}
|
| +namespace {{namespace}} {
|
| +{% endfor %}
|
|
|
| namespace {
|
|
|
| @@ -28,6 +29,35 @@ const char* const nullString = "null";
|
| const char* const trueString = "true";
|
| const char* const falseString = "false";
|
|
|
| +bool isASCII(UChar c)
|
| +{
|
| + return !(c & ~0x7F);
|
| +}
|
| +
|
| +bool isSpaceOrNewLine(UChar c)
|
| +{
|
| + return isASCII(c) && c <= ' ' && (c == ' ' || (c <= 0xD && c >= 0x9));
|
| +}
|
| +
|
| +double charactersToDouble(const UChar* characters, size_t length, bool* ok)
|
| +{
|
| + std::vector<char> buffer;
|
| + buffer.reserve(length + 1);
|
| + for (size_t i = 0; i < length; ++i) {
|
| + if (!isASCII(characters[i])) {
|
| + *ok = false;
|
| + return 0;
|
| + }
|
| + buffer.push_back(static_cast<char>(characters[i]));
|
| + }
|
| + buffer.push_back('\0');
|
| +
|
| + char* endptr;
|
| + double result = std::strtod(buffer.data(), &endptr);
|
| + *ok = !(*endptr);
|
| + return result;
|
| +}
|
| +
|
| bool parseConstToken(const UChar* start, const UChar* end, const UChar** tokenEnd, const char* token)
|
| {
|
| while (start < end && *token != '\0' && *start++ == *token++) { }
|
| @@ -195,7 +225,7 @@ bool skipComment(const UChar* start, const UChar* end, const UChar** commentEnd)
|
| void skipWhitespaceAndComments(const UChar* start, const UChar* end, const UChar** whitespaceEnd)
|
| {
|
| while (start < end) {
|
| - if (String16::isSpaceOrNewLine(*start)) {
|
| + if (isSpaceOrNewLine(*start)) {
|
| ++start;
|
| } else if (*start == '/') {
|
| const UChar* commentEnd;
|
| @@ -282,7 +312,7 @@ inline int hexToInt(UChar c)
|
| return 0;
|
| }
|
|
|
| -bool decodeString(const UChar* start, const UChar* end, String16Builder* output)
|
| +bool decodeString(const UChar* start, const UChar* end, StringBuilder* output)
|
| {
|
| while (start < end) {
|
| UChar c = *start++;
|
| @@ -335,7 +365,7 @@ bool decodeString(const UChar* start, const UChar* end, String16Builder* output)
|
| return true;
|
| }
|
|
|
| -bool decodeString(const UChar* start, const UChar* end, String16* output)
|
| +bool decodeString(const UChar* start, const UChar* end, String* output)
|
| {
|
| if (start == end) {
|
| *output = "";
|
| @@ -343,8 +373,8 @@ bool decodeString(const UChar* start, const UChar* end, String16* output)
|
| }
|
| if (start > end)
|
| return false;
|
| - String16Builder buffer;
|
| - buffer.reserveCapacity(end - start);
|
| + StringBuilder buffer;
|
| + StringUtil::builderReserve(buffer, end - start);
|
| if (!decodeString(start, end, &buffer))
|
| return false;
|
| *output = buffer.toString();
|
| @@ -374,7 +404,7 @@ std::unique_ptr<Value> buildValue(const UChar* start, const UChar* end, const UC
|
| break;
|
| case Number: {
|
| bool ok;
|
| - double value = String16::charactersToDouble(tokenStart, tokenEnd - tokenStart, &ok);
|
| + double value = charactersToDouble(tokenStart, tokenEnd - tokenStart, &ok);
|
| if (!ok)
|
| return nullptr;
|
| int number = static_cast<int>(value);
|
| @@ -385,7 +415,7 @@ std::unique_ptr<Value> buildValue(const UChar* start, const UChar* end, const UC
|
| break;
|
| }
|
| case StringLiteral: {
|
| - String16 value;
|
| + String value;
|
| bool ok = decodeString(tokenStart + 1, tokenEnd - 1, &value);
|
| if (!ok)
|
| return nullptr;
|
| @@ -427,7 +457,7 @@ std::unique_ptr<Value> buildValue(const UChar* start, const UChar* end, const UC
|
| while (token != ObjectEnd) {
|
| if (token != StringLiteral)
|
| return nullptr;
|
| - String16 key;
|
| + String key;
|
| if (!decodeString(tokenStart + 1, tokenEnd - 1, &key))
|
| return nullptr;
|
| start = tokenEnd;
|
| @@ -483,12 +513,16 @@ std::unique_ptr<Value> parseJSONInternal(const UChar* start, unsigned length)
|
|
|
| } // anonymous namespace
|
|
|
| -std::unique_ptr<Value> parseJSON(const String16& json)
|
| +std::unique_ptr<Value> parseJSON(const String& json)
|
| {
|
| - if (json.isEmpty())
|
| + const UChar* characters = nullptr;
|
| + size_t length = 0;
|
| + StringUtil::toCharacters(json, &characters, &length);
|
| + if (!length)
|
| return nullptr;
|
| - return parseJSONInternal(json.characters16(), json.length());
|
| + return parseJSONInternal(characters, length);
|
| }
|
|
|
| -} // namespace protocol
|
| -} // namespace blink
|
| +{% for namespace in config.protocol.namespace %}
|
| +} // namespace {{namespace}}
|
| +{% endfor %}
|
|
|