CSSSelector::PseudoElementType CSSSelector::parsePseudoElementType(const String& name) { if (name.isNull()) return PseudoElementUnknown; PseudoElementType type = parsePseudoElementString(*name.impl()); if (type == PseudoElementUnknown) { if (name.startsWith("-webkit-")) type = PseudoElementWebKitCustom; if (name.startsWith("x-")) type = PseudoElementUserAgentCustom; } return type; }
void DocumentWriter::appendReplacingData(const String& source) { ASSERT(!m_hasReceivedSomeData); m_hasReceivedSomeData = true; m_document->setCompatibilityMode(Document::NoQuirksMode); // FIXME: This should call DocumentParser::appendBytes instead of append // to support RawDataDocumentParsers. if (DocumentParser* parser = m_document->parser()) { parser->pinToMainThread(); // Because we're pinned to the main thread we don't need to worry about // passing ownership of the source string. parser->append(source.impl()); } }
void HTMLScriptElement::setText(const String &value) { ExceptionCode ec = 0; int numChildren = childNodeCount(); if (numChildren == 1 && firstChild()->isTextNode()) { static_cast<Text*>(firstChild())->setData(value, ec); return; } if (numChildren > 0) removeChildren(); appendChild(document()->createTextNode(value.impl()), ec); }
String MathMLMencloseElement::longDivLeftPadding() const { StringBuilder padding; float fontSize = 0; String closingBrace = ")"; TextRun run(closingBrace.impl(), closingBrace.length()); Node* node = parentNode(); if (node && node->renderer()) { const Font& font = node->renderer()->style().font(); fontSize = font.width(run); padding.append(String::number(fontSize)); padding.append("px"); } return padding.toString(); }
void LayoutMenuList::setText(const String& s) { if (s.isEmpty()) { // FIXME: This is a hack. We need the select to have the same baseline positioning as // any surrounding text. Wihtout any content, we align the bottom of the select to the bottom // of the text. With content (In this case the faked " ") we correctly align the middle of // the select to the middle of the text. It should be possible to remove this, just set // s.impl() into the text and have things align correctly ... crbug.com/485982 m_isEmpty = true; m_buttonText->setText(StringImpl::create(" ", 1), true); } else { m_isEmpty = false; m_buttonText->setText(s.impl(), true); } adjustInnerStyle(); }
void RenderButton::setText(const String& str) { if (str.isEmpty()) { if (m_buttonText) { m_buttonText->destroy(); m_buttonText = 0; } } else { if (m_buttonText) m_buttonText->setText(str.impl()); else { m_buttonText = new RenderTextFragment(document(), str); addChild(m_buttonText); } } }
void CharacterData::appendData(const String& arg, ExceptionCode&) { String newStr = m_data; newStr.append(arg); RefPtr<StringImpl> oldStr = m_data; m_data = newStr.impl(); if ((!renderer() || !rendererIsNeeded(renderer()->style())) && attached()) { detach(); attach(); } else if (renderer()) static_cast<RenderText*>(renderer())->setTextWithOffset(m_data, oldStr->length(), 0); dispatchModifiedEvent(oldStr.get()); }
String encodeForFileName(const String& inputString) { StringBuilder result; StringImpl* stringImpl = inputString.impl(); unsigned length = inputString.length(); for (unsigned i = 0; i < length; ++i) { UChar character = (*stringImpl)[i]; if (shouldEscapeUChar(character)) { result.append('%'); appendByteAsHex(character, result); } else result.append(character); } return result.toString(); }
void HTMLScriptElement::setText(const String &value) { RefPtr<Node> protectFromMutationEvents(this); int numChildren = childNodeCount(); if (numChildren == 1 && firstChild()->isTextNode()) { toText(firstChild())->setData(value); return; } if (numChildren > 0) removeChildren(); appendChild(document()->createTextNode(value.impl()), IGNORE_EXCEPTION); }
IdentifierRep* IdentifierRep::get(const char* name) { ASSERT(name); if (!name) return 0; String string = String::fromUTF8WithLatin1Fallback(name, strlen(name)); StringIdentifierMap::AddResult result = stringIdentifierMap().add(string.impl(), nullptr); if (result.isNewEntry) { ASSERT(!result.iterator->value); result.iterator->value = new IdentifierRep(name); identifierSet().add(result.iterator->value); } return result.iterator->value; }
static void removeItemFromMap(HTMLDocument::NameCountMap& map, const String& name) { if (name.length() == 0) return; HTMLDocument::NameCountMap::iterator it = map.find(name.impl()); if (it == map.end()) return; int oldVal = it->second; assert(oldVal != 0); int newVal = oldVal - 1; if (newVal == 0) map.remove(it); else it->second = newVal; }
void ResourceHandle::checkAndSendCookies(KURL& url) { // Cookies are a part of the http protocol only if (!String(d->m_url).startsWith("http")) return; if (url.isEmpty()) url = KURL(ParsedURLString, d->m_url); // Prepare a cookie header if there are cookies related to this url. String cookiePairs = cookieManager().getCookie(url, WithHttpOnlyCookies); if (!cookiePairs.isEmpty() && d->m_handle) { Vector<char> cookieChar = cookiePairs.impl()->ascii(); LOG(Network, "CURL POST Cookie : %s \n", cookieChar.data()); curl_easy_setopt(d->m_handle, CURLOPT_COOKIE, cookieChar.data()); } }
JSC::JSValue jsStringWithCache(JSC::ExecState* exec, const String& s) { JSC::VM& vm = exec->vm(); StringImpl* stringImpl = s.impl(); if (!stringImpl || !stringImpl->length()) return jsEmptyString(&vm); if (stringImpl->length() == 1) { UChar singleCharacter = (*stringImpl)[0u]; if (singleCharacter <= JSC::maxSingleCharacterString) return vm.smallStrings.singleCharacterString(static_cast<unsigned char>(singleCharacter)); } auto addResult = vm.stringCache.add(stringImpl, nullptr); if (addResult.isNewEntry) addResult.iterator->value = JSC::jsString(&vm, String(stringImpl)); return JSC::JSValue(addResult.iterator->value.get()); }
static inline SourceCode jscSource(const char* utf8, const UString& filename) { // Find the the first non-ascii character, or nul. const char* pos = utf8; while (*pos > 0) pos++; size_t asciiLength = pos - utf8; // Fast case - string is all ascii. if (!*pos) return makeSource(UString(utf8, asciiLength), filename); // Slow case - contains non-ascii characters, use fromUTF8WithLatin1Fallback. ASSERT(*pos < 0); ASSERT(strlen(utf8) == asciiLength + strlen(pos)); String source = String::fromUTF8WithLatin1Fallback(utf8, asciiLength + strlen(pos)); return makeSource(source.impl(), filename); }
void CSSPrimitiveValue::setStringValue(unsigned short stringType, const String& stringValue, ExceptionCode& ec) { ec = 0; if (m_type < CSS_STRING || m_type > CSS_ATTR || stringType < CSS_STRING || stringType > CSS_ATTR) { ec = INVALID_ACCESS_ERR; return; } cleanup(); if (stringType != CSS_IDENT) { m_value.string = stringValue.impl(); m_value.string->ref(); m_type = stringType; } // FIXME: parse ident }
void CharacterData::deleteData(unsigned offset, unsigned count, ExceptionCode& ec) { checkCharDataOperation(offset, ec); if (ec) return; unsigned realCount; if (offset + count > length()) realCount = length() - offset; else realCount = count; String newStr = m_data; newStr.remove(offset, realCount); setDataAndUpdate(newStr.impl(), offset, count, 0); document()->textRemoved(this, offset, realCount); }
String StackVisitor::Frame::sourceURL() { String traceLine; switch (codeType()) { case CodeType::Eval: case CodeType::Function: case CodeType::Global: { String sourceURL = codeBlock()->ownerExecutable()->sourceURL(); if (!sourceURL.isEmpty()) traceLine = sourceURL.impl(); break; } case CodeType::Native: traceLine = ASCIILiteral("[native code]"); break; } return traceLine.isNull() ? emptyString() : traceLine; }
void Attr::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta) { if (m_ignoreChildrenChanged > 0) return; Node::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta); // FIXME: We should include entity references in the value String val = ""; for (Node *n = firstChild(); n; n = n->nextSibling()) { if (n->isTextNode()) val += static_cast<Text *>(n)->data(); } m_attribute->setValue(val.impl()); if (m_element) m_element->attributeChanged(m_attribute.get()); }
void FirstLetterPseudoElement::attachFirstLetterTextLayoutObjects() { LayoutObject* nextLayoutObject = FirstLetterPseudoElement::firstLetterTextLayoutObject(*this); ASSERT(nextLayoutObject); ASSERT(nextLayoutObject->isText()); // The original string is going to be either a generated content string or a DOM node's // string. We want the original string before it got transformed in case first-letter has // no text-transform or a different text-transform applied to it. String oldText = toLayoutText(nextLayoutObject)->isTextFragment() ? toLayoutTextFragment(nextLayoutObject)->completeText() : toLayoutText(nextLayoutObject)->originalText(); ASSERT(oldText.impl()); ComputedStyle* pseudoStyle = styleForFirstLetter(nextLayoutObject->parent()); layoutObject()->setStyle(pseudoStyle); // FIXME: This would already have been calculated in firstLetterLayoutObject. Can we pass the length through? unsigned length = FirstLetterPseudoElement::firstLetterLength(oldText); // Construct a text fragment for the text after the first letter. // This text fragment might be empty. LayoutTextFragment* remainingText = new LayoutTextFragment(nextLayoutObject->node() ? nextLayoutObject->node() : &nextLayoutObject->document(), oldText.impl(), length, oldText.length() - length); remainingText->setFirstLetterPseudoElement(this); remainingText->setIsRemainingTextLayoutObject(true); remainingText->setStyle(nextLayoutObject->mutableStyle()); if (remainingText->node()) remainingText->node()->setLayoutObject(remainingText); m_remainingTextLayoutObject = remainingText; LayoutObject* nextSibling = layoutObject()->nextSibling(); layoutObject()->parent()->addChild(remainingText, nextSibling); // Construct text fragment for the first letter. LayoutTextFragment* letter = new LayoutTextFragment(&nextLayoutObject->document(), oldText.impl(), 0, length); letter->setFirstLetterPseudoElement(this); letter->setStyle(pseudoStyle); layoutObject()->addChild(letter); nextLayoutObject->destroy(); }
// The destination is 16bits, at least one string is 16 bits. static inline void appendStringToData(UChar*& data, const String& string) { if (string.isNull()) return; unsigned length = string.length(); const StringImpl* stringImpl = string.impl(); if (stringImpl->is8Bit()) { for (unsigned i = 0; i < length; ++i) { *data = stringImpl->characters8()[i]; ++data; } } else { for (unsigned i = 0; i < length; ++i) { *data = stringImpl->characters16()[i]; ++data; } } }
static void addToAccessControlAllowList(const String& string, unsigned start, unsigned end, HashSet<String, HashType>& set) { StringImpl* stringImpl = string.impl(); if (!stringImpl) return; // Skip white space from start. while (start <= end && isSpaceOrNewline((*stringImpl)[start])) ++start; // only white space if (start > end) return; // Skip white space from end. while (end && isSpaceOrNewline((*stringImpl)[end])) --end; set.add(string.substring(start, end - start + 1)); }
void PreflightResultCacheItem::addToAccessControlAllowList(const String& string, unsigned start, unsigned end, HashSet<String, HashType>& set) { StringImpl* stringImpl = string.impl(); if (!stringImpl) return; // Skip white space from start. while (start <= end && isSpaceOrNewline((*stringImpl)[start])) start++; // only white space if (start > end) return; // Skip white space from end. while (end && isSpaceOrNewline((*stringImpl)[end])) end--; // substringCopy() is called on the strings because the cache is accessed on multiple threads. set.add(string.substringCopy(start, end - start + 1)); }
TEST(WTF, StringImplReplaceWithLiteral) { RefPtr<StringImpl> testStringImpl = StringImpl::createFromLiteral("1224"); ASSERT_TRUE(testStringImpl->is8Bit()); // Cases for 8Bit source. testStringImpl = testStringImpl->replace('2', "", 0); ASSERT_TRUE(equal(testStringImpl.get(), "14")); testStringImpl = StringImpl::createFromLiteral("1224"); ASSERT_TRUE(testStringImpl->is8Bit()); testStringImpl = testStringImpl->replace('3', "NotFound", 8); ASSERT_TRUE(equal(testStringImpl.get(), "1224")); testStringImpl = testStringImpl->replace('2', "3", 1); ASSERT_TRUE(equal(testStringImpl.get(), "1334")); testStringImpl = StringImpl::createFromLiteral("1224"); ASSERT_TRUE(testStringImpl->is8Bit()); testStringImpl = testStringImpl->replace('2', "555", 3); ASSERT_TRUE(equal(testStringImpl.get(), "15555554")); // Cases for 16Bit source. String testString = String::fromUTF8("résumé"); ASSERT_FALSE(testString.impl()->is8Bit()); testStringImpl = testString.impl()->replace('2', "NotFound", 8); ASSERT_TRUE(equal(testStringImpl.get(), String::fromUTF8("résumé").impl())); testStringImpl = testString.impl()->replace(UChar(0x00E9 /*U+00E9 is 'é'*/), "e", 1); ASSERT_TRUE(equal(testStringImpl.get(), "resume")); testString = String::fromUTF8("résumé"); ASSERT_FALSE(testString.impl()->is8Bit()); testStringImpl = testString.impl()->replace(UChar(0x00E9 /*U+00E9 is 'é'*/), "", 0); ASSERT_TRUE(equal(testStringImpl.get(), "rsum")); testString = String::fromUTF8("résumé"); ASSERT_FALSE(testString.impl()->is8Bit()); testStringImpl = testString.impl()->replace(UChar(0x00E9 /*U+00E9 is 'é'*/), "555", 3); ASSERT_TRUE(equal(testStringImpl.get(), "r555sum555")); }
OpaqueJSClassContextData::OpaqueJSClassContextData(JSC::VM&, OpaqueJSClass* jsClass) : m_class(jsClass) { if (jsClass->m_staticValues) { staticValues = std::make_unique<OpaqueJSClassStaticValuesTable>(); OpaqueJSClassStaticValuesTable::const_iterator end = jsClass->m_staticValues->end(); for (OpaqueJSClassStaticValuesTable::const_iterator it = jsClass->m_staticValues->begin(); it != end; ++it) { ASSERT(!it->key->isAtomic()); String valueName = it->key->isolatedCopy(); staticValues->add(valueName.impl(), std::make_unique<StaticValueEntry>(it->value->getProperty, it->value->setProperty, it->value->attributes, valueName)); } } if (jsClass->m_staticFunctions) { staticFunctions = std::make_unique<OpaqueJSClassStaticFunctionsTable>(); OpaqueJSClassStaticFunctionsTable::const_iterator end = jsClass->m_staticFunctions->end(); for (OpaqueJSClassStaticFunctionsTable::const_iterator it = jsClass->m_staticFunctions->begin(); it != end; ++it) { ASSERT(!it->key->isAtomic()); staticFunctions->add(it->key->isolatedCopy(), std::make_unique<StaticFunctionEntry>(it->value->callAsFunction, it->value->attributes)); } } }
void CharacterData::insertData(unsigned offset, const String& arg, ExceptionCode& ec) { checkCharDataOperation(offset, ec); if (ec) return; String newStr = m_data; newStr.insert(arg, offset); RefPtr<StringImpl> oldStr = m_data; m_data = newStr.impl(); if ((!renderer() || !rendererIsNeeded(renderer()->style())) && attached()) { detach(); attach(); } else if (renderer()) static_cast<RenderText*>(renderer())->setTextWithOffset(m_data, offset, 0); dispatchModifiedEvent(oldStr.get()); document()->textInserted(this, offset, arg.length()); }
static bool isSVG10Feature(const String &feature) { static bool initialized = false; static HashSet<StringImpl*, CaseInsensitiveHash<StringImpl*> > svgFeatures; if (!initialized) { // TODO: features need to be uncommented when we implement them // 1.0 features addString(svgFeatures, "svg"); addString(svgFeatures, "svg.static"); // addString(svgFeatures, "svg.animation"); // addString(svgFeatures, "svg.dynamic"); // addString(svgFeatures, "svg.dom.animation"); // addString(svgFeatures, "svg.dom.dynamic"); addString(svgFeatures, "dom"); addString(svgFeatures, "dom.svg"); addString(svgFeatures, "dom.svg.static"); // addString(svgFeatures, "svg.all"); // addString(svgFeatures, "dom.svg.all"); initialized = true; } return svgFeatures.contains(feature.impl()); }
void CharacterData::replaceData(unsigned offset, unsigned count, const String& data, ExceptionCode& ec) { checkCharDataOperation(offset, ec); if (ec) return; unsigned realCount; if (offset + count > length()) realCount = length() - offset; else realCount = count; String newStr = m_data; newStr.remove(offset, realCount); newStr.insert(data, offset); setDataAndUpdate(newStr.impl(), offset, count, data.length()); // update the markers for spell checking and grammar checking document()->textRemoved(this, offset, realCount); document()->textInserted(this, offset, data.length()); }
static bool canSetRequestHeader(const String& name) { static HashSet<StringImpl*, CaseInsensitiveHash > forbiddenHeaders; if (forbiddenHeaders.isEmpty()) { forbiddenHeaders.add(new StringImpl("accept-charset")); forbiddenHeaders.add(new StringImpl("accept-encoding")); forbiddenHeaders.add(new StringImpl("content-length")); forbiddenHeaders.add(new StringImpl("expect")); forbiddenHeaders.add(new StringImpl("date")); forbiddenHeaders.add(new StringImpl("host")); forbiddenHeaders.add(new StringImpl("keep-alive")); forbiddenHeaders.add(new StringImpl("referer")); forbiddenHeaders.add(new StringImpl("te")); forbiddenHeaders.add(new StringImpl("trailer")); forbiddenHeaders.add(new StringImpl("transfer-encoding")); forbiddenHeaders.add(new StringImpl("upgrade")); forbiddenHeaders.add(new StringImpl("via")); } return !forbiddenHeaders.contains(name.impl()); }
OpaqueJSClassContextData::OpaqueJSClassContextData(JSC::VM&, OpaqueJSClass* jsClass) : m_class(jsClass) { if (jsClass->m_staticValues) { staticValues = adoptPtr(new OpaqueJSClassStaticValuesTable); OpaqueJSClassStaticValuesTable::const_iterator end = jsClass->m_staticValues->end(); for (OpaqueJSClassStaticValuesTable::const_iterator it = jsClass->m_staticValues->begin(); it != end; ++it) { ASSERT(!it->key->isIdentifier()); String valueName = it->key->isolatedCopy(); staticValues->add(valueName.impl(), adoptPtr(new StaticValueEntry(it->value->getProperty, it->value->setProperty, it->value->attributes, valueName))); } } if (jsClass->m_staticFunctions) { staticFunctions = adoptPtr(new OpaqueJSClassStaticFunctionsTable); OpaqueJSClassStaticFunctionsTable::const_iterator end = jsClass->m_staticFunctions->end(); for (OpaqueJSClassStaticFunctionsTable::const_iterator it = jsClass->m_staticFunctions->begin(); it != end; ++it) { ASSERT(!it->key->isIdentifier()); staticFunctions->add(it->key->isolatedCopy(), adoptPtr(new StaticFunctionEntry(it->value->callAsFunction, it->value->attributes))); } } }
String StackVisitor::Frame::sourceURL() const { String traceLine; switch (codeType()) { case CodeType::Eval: case CodeType::Module: case CodeType::Function: case CodeType::Global: { String sourceURL = codeBlock()->ownerExecutable()->sourceURL(); if (!sourceURL.isEmpty()) traceLine = sourceURL.impl(); break; } case CodeType::Native: traceLine = "[native code]"_s; break; case CodeType::Wasm: traceLine = "[wasm code]"_s; break; } return traceLine.isNull() ? emptyString() : traceLine; }