Adapt StringBuilder's append and toString methods via StringUtil helper.

This is needed to insulate generated code from blink::protocol namespace
from naming changes that we plan to do in the Great Blink Rename (which
in particular will change wtf::StringBuilder::toString into ToString,
and similarily will rename reserveCapacity and append methods).

This CL also includes roll of inspector_protocol which starts to
generate code that uses the new methods of StringUtil adapter:
rolling third_party/inspector to 1a131872167f0f7653629326891aa3ec94417f27.

BUG=683447

Review-Url: https://codereview.chromium.org/2660503002
Cr-Commit-Position: refs/heads/master@{#42750}
This commit is contained in:
lukasza 2017-01-27 13:11:15 -08:00 committed by Commit bot
parent 966355585b
commit 01a93925c1
5 changed files with 51 additions and 39 deletions

View File

@ -33,9 +33,21 @@ class StringUtil {
}
static String fromDouble(double number) { return String::fromDouble(number); }
static const size_t kNotFound = String::kNotFound;
static void builderAppend(StringBuilder& builder, const String& s) {
builder.append(s);
}
static void builderAppend(StringBuilder& builder, UChar c) {
builder.append(c);
}
static void builderAppend(StringBuilder& builder, const char* s, size_t len) {
builder.append(s, len);
}
static void builderReserve(StringBuilder& builder, size_t capacity) {
builder.reserveCapacity(capacity);
}
static String builderToString(StringBuilder& builder) {
return builder.toString();
}
static std::unique_ptr<protocol::Value> parseJSON(const String16& json);
static std::unique_ptr<protocol::Value> parseJSON(const StringView& json);
};

View File

@ -2,7 +2,7 @@ Name: inspector protocol
Short Name: inspector_protocol
URL: https://chromium.googlesource.com/deps/inspector_protocol/
Version: 0
Revision: 715b83a3cfb45ce6c67b6c6fdd2c16391b5db896
Revision: 1a131872167f0f7653629326891aa3ec94417f27
License: BSD
License File: LICENSE
Security Critical: no

View File

@ -32,12 +32,12 @@ void ErrorSupport::addError(const String& error)
StringBuilder builder;
for (size_t i = 0; i < m_path.size(); ++i) {
if (i)
builder.append('.');
builder.append(m_path[i]);
StringUtil::builderAppend(builder, '.');
StringUtil::builderAppend(builder, m_path[i]);
}
builder.append(": ");
builder.append(error);
m_errors.push_back(builder.toString());
StringUtil::builderAppend(builder, ": ");
StringUtil::builderAppend(builder, error);
m_errors.push_back(StringUtil::builderToString(builder));
}
bool ErrorSupport::hasErrors()
@ -50,10 +50,10 @@ String ErrorSupport::errors()
StringBuilder builder;
for (size_t i = 0; i < m_errors.size(); ++i) {
if (i)
builder.append("; ");
builder.append(m_errors[i]);
StringUtil::builderAppend(builder, "; ");
StringUtil::builderAppend(builder, m_errors[i]);
}
return builder.toString();
return StringUtil::builderToString(builder);
}
{% for namespace in config.protocol.namespace %}

View File

@ -337,7 +337,7 @@ bool decodeString(const Char* start, const Char* end, StringBuilder* output)
while (start < end) {
uint16_t c = *start++;
if ('\\' != c) {
output->append(c);
StringUtil::builderAppend(*output, c);
continue;
}
if (start == end)
@ -382,7 +382,7 @@ bool decodeString(const Char* start, const Char* end, StringBuilder* output)
default:
return false;
}
output->append(c);
StringUtil::builderAppend(*output, c);
}
return true;
}
@ -400,7 +400,7 @@ bool decodeString(const Char* start, const Char* end, String* output)
StringUtil::builderReserve(buffer, end - start);
if (!decodeString(start, end, &buffer))
return false;
*output = buffer.toString();
*output = StringUtil::builderToString(buffer);
return true;
}

View File

@ -17,13 +17,13 @@ const char* const falseValueString = "false";
inline bool escapeChar(uint16_t c, StringBuilder* dst)
{
switch (c) {
case '\b': dst->append("\\b"); break;
case '\f': dst->append("\\f"); break;
case '\n': dst->append("\\n"); break;
case '\r': dst->append("\\r"); break;
case '\t': dst->append("\\t"); break;
case '\\': dst->append("\\\\"); break;
case '"': dst->append("\\\""); break;
case '\b': StringUtil::builderAppend(*dst, "\\b"); break;
case '\f': StringUtil::builderAppend(*dst, "\\f"); break;
case '\n': StringUtil::builderAppend(*dst, "\\n"); break;
case '\r': StringUtil::builderAppend(*dst, "\\r"); break;
case '\t': StringUtil::builderAppend(*dst, "\\t"); break;
case '\\': StringUtil::builderAppend(*dst, "\\\\"); break;
case '"': StringUtil::builderAppend(*dst, "\\\""); break;
default:
return false;
}
@ -34,10 +34,10 @@ const char hexDigits[17] = "0123456789ABCDEF";
void appendUnsignedAsHex(uint16_t number, StringBuilder* dst)
{
dst->append("\\u");
StringUtil::builderAppend(*dst, "\\u");
for (size_t i = 0; i < 4; ++i) {
uint16_t c = hexDigits[(number & 0xF000) >> 12];
dst->append(c);
StringUtil::builderAppend(*dst, c);
number <<= 4;
}
}
@ -53,7 +53,7 @@ void escapeStringForJSON(const String& str, StringBuilder* dst)
// is also optional. It would also be a pain to implement here.
appendUnsignedAsHex(c, dst);
} else {
dst->append(c);
StringUtil::builderAppend(*dst, c);
}
}
}
@ -61,9 +61,9 @@ void escapeStringForJSON(const String& str, StringBuilder* dst)
void doubleQuoteStringForJSON(const String& str, StringBuilder* dst)
{
dst->append('"');
StringUtil::builderAppend(*dst, '"');
escapeStringForJSON(str, dst);
dst->append('"');
StringUtil::builderAppend(*dst, '"');
}
} // anonymous namespace
@ -96,7 +96,7 @@ bool Value::asSerialized(String*) const
void Value::writeJSON(StringBuilder* output) const
{
DCHECK(m_type == TypeNull);
output->append(nullValueString, 4);
StringUtil::builderAppend(*output, nullValueString, 4);
}
std::unique_ptr<Value> Value::clone() const
@ -109,7 +109,7 @@ String Value::serialize()
StringBuilder result;
StringUtil::builderReserve(result, 512);
writeJSON(&result);
return result.toString();
return StringUtil::builderToString(result);
}
bool FundamentalValue::asBoolean(bool* output) const
@ -146,17 +146,17 @@ void FundamentalValue::writeJSON(StringBuilder* output) const
DCHECK(type() == TypeBoolean || type() == TypeInteger || type() == TypeDouble);
if (type() == TypeBoolean) {
if (m_boolValue)
output->append(trueValueString, 4);
StringUtil::builderAppend(*output, trueValueString, 4);
else
output->append(falseValueString, 5);
StringUtil::builderAppend(*output, falseValueString, 5);
} else if (type() == TypeDouble) {
if (!std::isfinite(m_doubleValue)) {
output->append(nullValueString, 4);
StringUtil::builderAppend(*output, nullValueString, 4);
return;
}
output->append(StringUtil::fromDouble(m_doubleValue));
StringUtil::builderAppend(*output, StringUtil::fromDouble(m_doubleValue));
} else if (type() == TypeInteger) {
output->append(StringUtil::fromInteger(m_integerValue));
StringUtil::builderAppend(*output, StringUtil::fromInteger(m_integerValue));
}
}
@ -198,7 +198,7 @@ bool SerializedValue::asSerialized(String* output) const
void SerializedValue::writeJSON(StringBuilder* output) const
{
DCHECK(type() == TypeSerialized);
output->append(m_serializedValue);
StringUtil::builderAppend(*output, m_serializedValue);
}
std::unique_ptr<Value> SerializedValue::clone() const
@ -330,17 +330,17 @@ void DictionaryValue::remove(const String& name)
void DictionaryValue::writeJSON(StringBuilder* output) const
{
output->append('{');
StringUtil::builderAppend(*output, '{');
for (size_t i = 0; i < m_order.size(); ++i) {
Dictionary::const_iterator it = m_data.find(m_order[i]);
CHECK(it != m_data.end());
if (i)
output->append(',');
StringUtil::builderAppend(*output, ',');
doubleQuoteStringForJSON(it->first, output);
output->append(':');
StringUtil::builderAppend(*output, ':');
it->second->writeJSON(output);
}
output->append('}');
StringUtil::builderAppend(*output, '}');
}
std::unique_ptr<Value> DictionaryValue::clone() const
@ -366,15 +366,15 @@ ListValue::~ListValue()
void ListValue::writeJSON(StringBuilder* output) const
{
output->append('[');
StringUtil::builderAppend(*output, '[');
bool first = true;
for (const std::unique_ptr<protocol::Value>& value : m_data) {
if (!first)
output->append(',');
StringUtil::builderAppend(*output, ',');
value->writeJSON(output);
first = false;
}
output->append(']');
StringUtil::builderAppend(*output, ']');
}
std::unique_ptr<Value> ListValue::clone() const