static void appendLangArgumentList(StringBuilder& str, const Vector<AtomicString>& argumentList) { unsigned argumentListSize = argumentList.size(); for (unsigned i = 0; i < argumentListSize; ++i) { str.append('"'); str.append(argumentList[i]); str.append('"'); if (i != argumentListSize - 1) str.appendLiteral(", "); } }
String StylePropertySerializer::getPropertyText(CSSPropertyID propertyID, const String& value, bool isNotFirstDecl) const { StringBuilder result; if (isNotFirstDecl) result.append(' '); result.append(getPropertyName(propertyID)); result.appendLiteral(": "); result.append(value); result.append(';'); return result.toString(); }
static void appendBackgroundRepeatValue(StringBuilder& builder, const CSSValue& repeatXCSSValue, const CSSValue& repeatYCSSValue) { // FIXME: Ensure initial values do not appear in CSS_VALUE_LISTS. DEFINE_STATIC_REF_WILL_BE_PERSISTENT(CSSPrimitiveValue, initialRepeatValue, (CSSPrimitiveValue::create(CSSValueRepeat))); const CSSPrimitiveValue& repeatX = repeatXCSSValue.isInitialValue() ? *initialRepeatValue : toCSSPrimitiveValue(repeatXCSSValue); const CSSPrimitiveValue& repeatY = repeatYCSSValue.isInitialValue() ? *initialRepeatValue : toCSSPrimitiveValue(repeatYCSSValue); CSSValueID repeatXValueId = repeatX.getValueID(); CSSValueID repeatYValueId = repeatY.getValueID(); if (repeatXValueId == repeatYValueId) { builder.append(repeatX.cssText()); } else if (repeatXValueId == CSSValueNoRepeat && repeatYValueId == CSSValueRepeat) { builder.appendLiteral("repeat-y"); } else if (repeatXValueId == CSSValueRepeat && repeatYValueId == CSSValueNoRepeat) { builder.appendLiteral("repeat-x"); } else { builder.append(repeatX.cssText()); builder.appendLiteral(" "); builder.append(repeatY.cssText()); } }
String UnlinkedFunctionExecutable::paramString() const { FunctionParameters& parameters = *m_parameters; StringBuilder builder; for (size_t pos = 0; pos < parameters.size(); ++pos) { if (!builder.isEmpty()) builder.appendLiteral(", "); parameters.at(pos)->toString(builder); } return builder.toString(); }
String CSSFontFaceRule::cssText() const { StringBuilder result; result.appendLiteral("@font-face { "); String descs = m_fontFaceRule->properties().asText(); result.append(descs); if (!descs.isEmpty()) result.append(' '); result.append('}'); return result.toString(); }
void TrackBase::setLanguage(const AtomicString& language) { if (!language.isEmpty() && !isValidBCP47LanguageTag(language)) { String message; if (language.contains((UChar)'\0')) message = WTF::ASCIILiteral("The language contains a null character and is not a valid BCP 47 language tag."); else { StringBuilder stringBuilder; stringBuilder.appendLiteral("The language '"); stringBuilder.append(language); stringBuilder.appendLiteral("' is not a valid BCP 47 language tag."); message = stringBuilder.toString(); } if (auto element = this->element()) element->document().addConsoleMessage(MessageSource::Rendering, MessageLevel::Warning, message); } else m_validBCP47Language = language; m_language = language; }
void VisibleSelection::formatForDebugger(char* buffer, unsigned length) const { StringBuilder result; String s; if (isNone()) { result.appendLiteral("<none>"); } else { const int FormatBufferSize = 1024; char s[FormatBufferSize]; result.appendLiteral("from "); start().formatForDebugger(s, FormatBufferSize); result.append(s); result.appendLiteral(" to "); end().formatForDebugger(s, FormatBufferSize); result.append(s); } strncpy(buffer, result.toString().utf8().data(), length - 1); }
void FileReaderLoader::convertToDataURL() { StringBuilder builder; builder.appendLiteral("data:"); if (!m_bytesLoaded) { m_stringResult = builder.toString(); return; } builder.append(m_dataType); builder.appendLiteral(";base64,"); Vector<char> out; base64Encode(m_rawData->data(), m_bytesLoaded, out); out.append('\0'); builder.append(out.data()); m_stringResult = builder.toString(); }
void InspectorValue::writeJSON(StringBuilder& output) const { switch (m_type) { case Type::Null: output.appendLiteral("null"); break; case Type::Boolean: if (m_value.boolean) output.appendLiteral("true"); else output.appendLiteral("false"); break; case Type::String: doubleQuoteString(m_value.string, output); break; case Type::Double: case Type::Integer: { NumberToLStringBuffer buffer; if (!std::isfinite(m_value.number)) { output.appendLiteral("null"); return; } DecimalNumber decimal = m_value.number; unsigned length = 0; if (decimal.bufferLengthForStringDecimal() > WTF::NumberToStringBufferLength) { // Not enough room for decimal. Use exponential format. if (decimal.bufferLengthForStringExponential() > WTF::NumberToStringBufferLength) { // Fallback for an abnormal case if it's too little even for exponential. output.appendLiteral("NaN"); return; } length = decimal.toStringExponential(buffer, WTF::NumberToStringBufferLength); } else length = decimal.toStringDecimal(buffer, WTF::NumberToStringBufferLength); output.append(buffer, length); break; } default: ASSERT_NOT_REACHED(); } }
bool WebInspectorServer::platformResourceForPath(const String& path, Vector<char>& data, String& contentType) { // The page list contains an unformated list of pages that can be inspected with a link to open a session. if (path == "/pagelist.json") { buildPageList(data, contentType); return true; } // Point the default path to a formatted page that queries the page list and display them. CString localPath = WebCore::fileSystemRepresentation(inspectorServerFilesPath() + ((path == "/") ? "/inspectorPageIndex.html" : path)); if (localPath.isNull()) return false; GRefPtr<GFile> file = adoptGRef(g_file_new_for_path(localPath.data())); GOwnPtr<GError> error; GRefPtr<GFileInfo> fileInfo = adoptGRef(g_file_query_info(file.get(), G_FILE_ATTRIBUTE_STANDARD_SIZE "," G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, 0, &error.outPtr())); if (!fileInfo) { StringBuilder builder; builder.appendLiteral("<!DOCTYPE html><html><head></head><body>Error: "); builder.appendNumber(error->code); builder.appendLiteral(", "); builder.append(error->message); builder.appendLiteral(" occurred during fetching webinspector resource files.<br>Make sure you ran make install or have set WEBKIT_INSPECTOR_SERVER_PATH in your environment to point to webinspector folder.</body></html>"); CString cstr = builder.toString().utf8(); data.append(cstr.data(), cstr.length()); contentType = "text/html; charset=utf-8"; g_warning("Error fetching webinspector resource files: %d, %s", error->code, error->message); return true; } GRefPtr<GFileInputStream> inputStream = adoptGRef(g_file_read(file.get(), 0, 0)); if (!inputStream) return false; data.grow(g_file_info_get_size(fileInfo.get())); if (!g_input_stream_read_all(G_INPUT_STREAM(inputStream.get()), data.data(), data.size(), 0, 0, 0)) return false; contentType = GOwnPtr<gchar>(g_file_info_get_attribute_as_string(fileInfo.get(), G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE)).get(); return true; }
void EventSource::didReceiveResponse(unsigned long, const ResourceResponse& response) { ASSERT(m_state == CONNECTING); ASSERT(m_requestInFlight); m_eventStreamOrigin = SecurityOrigin::create(response.url())->toString(); int statusCode = response.httpStatusCode(); bool mimeTypeIsValid = response.mimeType() == "text/event-stream"; bool responseIsValid = statusCode == 200 && mimeTypeIsValid; if (responseIsValid) { const String& charset = response.textEncodingName(); // If we have a charset, the only allowed value is UTF-8 (case-insensitive). responseIsValid = charset.isEmpty() || equalIgnoringCase(charset, "UTF-8"); if (!responseIsValid) { StringBuilder message; message.appendLiteral("EventSource's response has a charset (\""); message.append(charset); message.appendLiteral("\") that is not UTF-8. Aborting the connection."); // FIXME: We are missing the source line. scriptExecutionContext()->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message.toString()); } } else { // To keep the signal-to-noise ratio low, we only log 200-response with an invalid MIME type. if (statusCode == 200 && !mimeTypeIsValid) { StringBuilder message; message.appendLiteral("EventSource's response has a MIME type (\""); message.append(response.mimeType()); message.appendLiteral("\") that is not \"text/event-stream\". Aborting the connection."); // FIXME: We are missing the source line. scriptExecutionContext()->addConsoleMessage(JSMessageSource, ErrorMessageLevel, message.toString()); } } if (responseIsValid) { m_state = OPEN; dispatchEvent(Event::create(eventNames().openEvent, false, false)); } else { m_loader->cancel(); dispatchEvent(Event::create(eventNames().errorEvent, false, false)); } }
inline void SecurityOrigin::buildRawString(StringBuilder& builder) const { builder.reserveCapacity(m_protocol.length() + m_host.length() + 10); builder.append(m_protocol); builder.appendLiteral("://"); builder.append(m_host); if (m_port) { builder.append(':'); builder.appendNumber(m_port); } }
String MediaQuerySet::mediaText() const { StringBuilder text; bool needComma = false; for (auto& query : m_queries) { if (needComma) text.appendLiteral(", "); text.append(query.cssText()); needComma = true; } return text.toString(); }
void Text::formatForDebugger(char* buffer, unsigned length) const { StringBuilder result; String s; result.append(nodeName()); s = data(); if (s.length() > 0) { if (result.length()) result.appendLiteral("; "); result.appendLiteral("length="); result.appendNumber(s.length()); result.appendLiteral("; value=\""); result.append(s); result.append('"'); } strncpy(buffer, result.toString().utf8().data(), length - 1); buffer[length - 1] = '\0'; }
String nodePositionAsStringForTesting(Node* node) { StringBuilder result; Node* parent; for (Node* n = node; n; n = parent) { parent = n->parentNode(); if (n != node) result.appendLiteral(" of "); if (parent) { result.appendLiteral("child "); result.appendNumber(n->nodeIndex()); result.appendLiteral(" {"); result.append(n->nodeName()); result.append('}'); } else result.appendLiteral("document"); } return result.toString(); }
String CSSStyleRule::cssText() const { StringBuilder result; result.append(selectorText()); result.appendLiteral(" { "); String decls = m_styleRule->properties().asText(); result.append(decls); if (!decls.isEmpty()) result.append(' '); result.append('}'); return result.toString(); }
String StyleKeyframe::cssText() const { StringBuilder result; result.append(keyText()); result.appendLiteral(" { "); String decls = m_properties->asText(); result.append(decls); if (!decls.isEmpty()) result.append(' '); result.append('}'); return result.toString(); }
static String buildCircleString(const String& radius, const String& centerX, const String& centerY) { char at[] = "at"; char separator[] = " "; StringBuilder result; result.appendLiteral("circle("); if (!radius.isNull()) result.append(radius); if (!centerX.isNull() || !centerY.isNull()) { if (!radius.isNull()) result.appendLiteral(separator); result.append(at); result.appendLiteral(separator); result.append(centerX); result.appendLiteral(separator); result.append(centerY); } result.append(')'); return result.toString(); }
String CSSSelectorList::selectorsText() const { StringBuilder result; for (const CSSSelector* s = first(); s; s = next(*s)) { if (s != first()) result.appendLiteral(", "); result.append(s->selectorText()); } return result.toString(); }
static String buildUserAgentString(const UserAgentQuirks& quirks) { StringBuilder uaString; uaString.appendLiteral("Mozilla/5.0 "); uaString.append('('); if (quirks.contains(UserAgentQuirks::NeedsMacintoshPlatform)) uaString.appendLiteral("Macintosh"); else uaString.append(platformForUAString()); uaString.appendLiteral("; "); if (quirks.contains(UserAgentQuirks::NeedsMacintoshPlatform)) { uaString.append(cpuDescriptionForUAString()); uaString.appendLiteral(" Mac OS X"); } else uaString.append(platformVersionForUAString()); uaString.appendLiteral(") AppleWebKit/"); uaString.append(versionForUAString()); // Version/X is mandatory *before* Safari/X to be a valid Safari UA. See // https://bugs.webkit.org/show_bug.cgi?id=133403 for details. uaString.appendLiteral(" (KHTML, like Gecko) Version/8.0 Safari/"); uaString.append(versionForUAString()); return uaString.toString(); }
static String buildEllipseString(const String& radiusX, const String& radiusY, const String& centerX, const String& centerY) { char at[] = "at"; char separator[] = " "; StringBuilder result; result.appendLiteral("ellipse("); bool needsSeparator = false; if (!radiusX.isNull()) { result.append(radiusX); needsSeparator = true; } if (!radiusY.isNull()) { if (needsSeparator) result.appendLiteral(separator); result.append(radiusY); needsSeparator = true; } if (!centerX.isNull() || !centerY.isNull()) { if (needsSeparator) result.appendLiteral(separator); result.appendLiteral(at); result.appendLiteral(separator); result.append(centerX); result.appendLiteral(separator); result.append(centerY); } result.append(')'); return result.toString(); }
String CSSLineBoxContainValue::customCssText() const { StringBuilder text; if (m_value & LineBoxContainBlock) text.appendLiteral("block"); if (m_value & LineBoxContainInline) { if (!text.isEmpty()) text.append(' '); text.appendLiteral("inline"); } if (m_value & LineBoxContainFont) { if (!text.isEmpty()) text.append(' '); text.appendLiteral("font"); } if (m_value & LineBoxContainGlyphs) { if (!text.isEmpty()) text.append(' '); text.appendLiteral("glyphs"); } if (m_value & LineBoxContainReplaced) { if (!text.isEmpty()) text.append(' '); text.appendLiteral("replaced"); } if (m_value & LineBoxContainInlineBox) { if (!text.isEmpty()) text.append(' '); text.appendLiteral("inline-box"); } return text.toString(); }
static String buildObjectStoreStatement(const IDBKeyRangeData& keyRange, IndexedDB::CursorDirection cursorDirection) { StringBuilder builder; builder.appendLiteral("SELECT rowid, key, value FROM Records WHERE objectStoreID = ? AND key "); if (!keyRange.lowerKey.isNull() && !keyRange.lowerOpen) builder.appendLiteral(">="); else builder.append('>'); builder.appendLiteral(" CAST(? AS TEXT) AND key "); if (!keyRange.upperKey.isNull() && !keyRange.upperOpen) builder.appendLiteral("<="); else builder.append('<'); builder.appendLiteral(" CAST(? AS TEXT) ORDER BY key"); if (cursorDirection == IndexedDB::CursorDirection::Prev || cursorDirection == IndexedDB::CursorDirection::PrevNoDuplicate) builder.appendLiteral(" DESC"); builder.append(';'); return builder.toString(); }
String GamepadData::loggingString() const { StringBuilder builder; builder.appendNumber(axisValues.size()); builder.appendLiteral(" axes, "); builder.appendNumber(buttonValues.size()); builder.appendLiteral(" buttons\n"); for (size_t i = 0; i < axisValues.size(); ++i) { builder.appendLiteral(" Axis "); builder.appendNumber(i); builder.appendLiteral(": "); builder.appendNumber(axisValues[i]); } builder.append('\n'); for (size_t i = 0; i < buttonValues.size(); ++i) { builder.appendLiteral(" Button "); builder.appendNumber(i); builder.appendLiteral(": "); builder.appendNumber(buttonValues[i]); } return builder.toString(); }
static String buildRectangleString(const String& x, const String& y, const String& width, const String& height, const String& radiusX, const String& radiusY, const String& layoutBox) { const char opening[] = "rectangle("; const char separator[] = ", "; StringBuilder result; // Compute the required capacity in advance to reduce allocations. result.reserveCapacity((sizeof(opening) - 1) + (5 * (sizeof(separator) - 1)) + 1 + x.length() + y.length() + width.length() + height.length() + radiusX.length() + radiusY.length() + (layoutBox.isEmpty() ? 0 : layoutBox.length() + 1)); result.appendLiteral(opening); result.append(x); result.appendLiteral(separator); result.append(y); result.appendLiteral(separator); result.append(width); result.appendLiteral(separator); result.append(height); if (!radiusX.isNull()) { result.appendLiteral(separator); result.append(radiusX); if (!radiusY.isNull()) { result.appendLiteral(separator); result.append(radiusY); } } if (!layoutBox.isEmpty()) { result.append(' '); result.append(layoutBox); } result.append(')'); return result.toString(); }
static String buildInsetRectangleString(const String& top, const String& right, const String& bottom, const String& left, const String& radiusX, const String& radiusY, const String& layoutBox) { const char opening[] = "inset-rectangle("; const char separator[] = ", "; StringBuilder result; // Compute the required capacity in advance to reduce allocations. result.reserveCapacity((sizeof(opening) - 1) + (5 * (sizeof(separator) - 1)) + 1 + top.length() + right.length() + bottom.length() + left.length() + radiusX.length() + radiusY.length() + (layoutBox.isEmpty() ? 0 : layoutBox.length() + 1)); result.appendLiteral(opening); result.append(top); result.appendLiteral(separator); result.append(right); result.appendLiteral(separator); result.append(bottom); result.appendLiteral(separator); result.append(left); if (!radiusX.isNull()) { result.appendLiteral(separator); result.append(radiusX); if (!radiusY.isNull()) { result.appendLiteral(separator); result.append(radiusY); } } result.append(')'); if (!layoutBox.isEmpty()) { result.append(' '); result.append(layoutBox); } return result.toString(); }
static String encodeProtocolString(const String& protocol) { StringBuilder builder; for (size_t i = 0; i < protocol.length(); i++) { if (protocol[i] < 0x20 || protocol[i] > 0x7E) builder.append(String::format("\\u%04X", protocol[i])); else if (protocol[i] == 0x5c) builder.appendLiteral("\\\\"); else builder.append(protocol[i]); } return builder.toString(); }
String MediaQueryExp::serialize() const { StringBuilder result; result.append('('); result.append(m_mediaFeature.lower()); if (m_expValue.isValid()) { result.appendLiteral(": "); result.append(m_expValue.cssText()); } result.append(')'); return result.toString(); }
static String imageTitle(const String& filename, const IntSize& size) { StringBuilder result; result.append(filename); result.appendLiteral(" ("); // FIXME: Localize numbers. Safari/OSX shows localized numbers with group // separaters. For example, "1,920x1,080". result.appendNumber(size.width()); result.append(static_cast<UChar>(0xD7)); // U+00D7 (multiplication sign) result.appendNumber(size.height()); result.append(')'); return result.toString(); }
String CSSMediaRule::cssText() const { StringBuilder result; result.append("@media "); if (mediaQueries()) { result.append(mediaQueries()->mediaText()); result.append(' '); } result.appendLiteral("{ \n"); appendCssTextForItems(result); result.append('}'); return result.toString(); }