void MarkupAccumulator::appendCharactersReplacingEntities(StringBuilder& result, const String& source, unsigned offset, unsigned length, EntityMask entityMask) { DEFINE_STATIC_LOCAL(const CString, ampReference, ("&")); DEFINE_STATIC_LOCAL(const CString, ltReference, ("<")); DEFINE_STATIC_LOCAL(const CString, gtReference, (">")); DEFINE_STATIC_LOCAL(const CString, quotReference, (""")); DEFINE_STATIC_LOCAL(const CString, nbspReference, (" ")); static const EntityDescription entityMaps[] = { { '&', ampReference, EntityAmp }, { '<', ltReference, EntityLt }, { '>', gtReference, EntityGt }, { '"', quotReference, EntityQuot }, { noBreakSpace, nbspReference, EntityNbsp }, }; if (!(offset + length)) return; ASSERT(offset + length <= source.length()); if (source.is8Bit()) appendCharactersReplacingEntitiesInternal(result, source.characters8() + offset, length, entityMaps, WTF_ARRAY_LENGTH(entityMaps), entityMask); else appendCharactersReplacingEntitiesInternal(result, source.characters16() + offset, length, entityMaps, WTF_ARRAY_LENGTH(entityMaps), entityMask); }
static String notAFunctionSourceAppender(const String& originalMessage, const String& sourceText, RuntimeType type, ErrorInstance::SourceTextWhereErrorOccurred occurrence) { ASSERT(type != TypeFunction); if (occurrence == ErrorInstance::FoundApproximateSource) return defaultApproximateSourceError(originalMessage, sourceText); ASSERT(occurrence == ErrorInstance::FoundExactSource); auto notAFunctionIndex = originalMessage.reverseFind("is not a function"); RELEASE_ASSERT(notAFunctionIndex != notFound); StringView displayValue; if (originalMessage.is8Bit()) displayValue = StringView(originalMessage.characters8(), notAFunctionIndex - 1); else displayValue = StringView(originalMessage.characters16(), notAFunctionIndex - 1); String base = functionCallBase(sourceText); StringBuilder builder; builder.append(base); builder.appendLiteral(" is not a function. (In '"); builder.append(sourceText); builder.appendLiteral("', '"); builder.append(base); builder.appendLiteral("' is "); if (type == TypeObject) builder.appendLiteral("an instance of "); builder.append(displayValue); builder.appendLiteral(")"); return builder.toString(); }
int nextBreakablePositionIgnoringNBSP(LazyLineBreakIterator& lazyBreakIterator, int pos) { String string = lazyBreakIterator.string(); if (string.is8Bit()) return nextBreakablePosition<LChar, false>(lazyBreakIterator, string.characters8(), string.length(), pos); return nextBreakablePosition<UChar, false>(lazyBreakIterator, string.characters16(), string.length(), pos); }
EncodedJSValue regExpObjectSource(ExecState* exec, JSObject* slotBase, EncodedJSValue, PropertyName) { String pattern = asRegExpObject(slotBase)->regExp()->pattern(); if (pattern.is8Bit()) return JSValue::encode(regExpObjectSourceInternal(exec, pattern, pattern.characters8(), pattern.length())); return JSValue::encode(regExpObjectSourceInternal(exec, pattern, pattern.characters16(), pattern.length())); }
static inline bool hasNonASCIIOrUpper(const String& string) { unsigned length = string.length(); if (string.is8Bit()) return hasNonASCIIOrUpper(string.characters8(), length); return hasNonASCIIOrUpper(string.characters16(), length); }
static bool propertyNameMatchesAttributeName(const String& propertyName, const String& attributeName) { if (!attributeName.startsWith("data-")) return false; unsigned propertyLength = propertyName.length(); unsigned attributeLength = attributeName.length(); if (propertyName.is8Bit()) { if (attributeName.is8Bit()) return propertyNameMatchesAttributeName(propertyName.characters8(), attributeName.characters8(), propertyLength, attributeLength); return propertyNameMatchesAttributeName(propertyName.characters8(), attributeName.characters16(), propertyLength, attributeLength); } if (attributeName.is8Bit()) return propertyNameMatchesAttributeName(propertyName.characters16(), attributeName.characters8(), propertyLength, attributeLength); return propertyNameMatchesAttributeName(propertyName.characters16(), attributeName.characters16(), propertyLength, attributeLength); }
static bool parseFontSize(const String& input, int& size) { if (input.isEmpty()) return false; if (input.is8Bit()) return parseFontSize(input.characters8(), input.length(), size); return parseFontSize(input.characters16(), input.length(), size); }
bool Color::parseHexColor(const String& name, RGBA32& rgb) { unsigned length = name.length(); if (!length) return false; if (name.is8Bit()) return parseHexColor(name.characters8(), name.length(), rgb); return parseHexColor(name.characters16(), name.length(), rgb); }
LinkHeaderSet::LinkHeaderSet(const String& header) { if (header.isNull()) return; if (header.is8Bit()) init(header.characters8(), header.length()); else init(header.characters16(), header.length()); }
static inline void addCaseFoldedCharacters(StringHasher& hasher, const String& string) { if (string.isEmpty()) return; if (string.is8Bit()) { hasher.addCharacters<LChar, CaseFoldingHash::foldCase<LChar>>(string.characters8(), string.length()); return; } hasher.addCharacters<UChar, CaseFoldingHash::foldCase<UChar>>(string.characters16(), string.length()); }
Color::Color(const String& name) { if (name[0] == '#') { if (name.is8Bit()) m_valid = parseHexColor(name.characters8() + 1, name.length() - 1, m_color); else m_valid = parseHexColor(name.characters16() + 1, name.length() - 1, m_color); } else { setNamedColor(name); } }
void SpaceSplitString::Data::createVector(const String& string) { unsigned length = string.length(); if (string.is8Bit()) { createVector(string.characters8(), length); return; } createVector(string.characters16(), length); }
String stripLeadingAndTrailingHTMLSpaces(const String& string) { unsigned length = string.length(); if (!length) return string.isNull() ? string : emptyAtom.string(); if (string.is8Bit()) return stripLeadingAndTrailingHTMLSpaces(string, string.characters8(), length); return stripLeadingAndTrailingHTMLSpaces(string, string.characters(), length); }
JSValueRef JSValueMakeFromJSONString(JSContextRef ctx, JSStringRef string) { ExecState* exec = toJS(ctx); APIEntryShim entryShim(exec); String str = string->string(); if (str.is8Bit()) { LiteralParser<LChar> parser(exec, str.characters8(), str.length(), StrictJSON); return toRef(exec, parser.tryLiteralParse()); } LiteralParser<UChar> parser(exec, str.characters16(), str.length(), StrictJSON); return toRef(exec, parser.tryLiteralParse()); }
// http://www.whatwg.org/specs/web-apps/current-work/#rules-for-parsing-non-negative-integers bool parseHTMLNonNegativeInteger(const String& input, unsigned& value) { // Step 1 // Step 2 unsigned length = input.length(); if (length && input.is8Bit()) { const LChar* start = input.characters8(); return parseHTMLNonNegativeIntegerInternal(start, start + length, value); } const UChar* start = input.characters(); return parseHTMLNonNegativeIntegerInternal(start, start + length, value); }
bool parseNumberOptionalNumber(const String& string, float& x, float& y) { if (string.isEmpty()) return false; if (string.is8Bit()) { const LChar* ptr = string.characters8(); const LChar* end = ptr + string.length(); return genericParseNumberOptionalNumber(ptr, end, x, y); } const UChar* ptr = string.characters16(); const UChar* end = ptr + string.length(); return genericParseNumberOptionalNumber(ptr, end, x, y); }
bool SVGViewSpec::parseViewSpec(const String& spec) { if (spec.isEmpty() || !m_contextElement) return false; if (spec.is8Bit()) { const LChar* ptr = spec.characters8(); const LChar* end = ptr + spec.length(); return parseViewSpecInternal(ptr, end); } const UChar* ptr = spec.characters16(); const UChar* end = ptr + spec.length(); return parseViewSpecInternal(ptr, end); }
bool parseNumberOrPercentage(const String& string, float& number) { if (string.isEmpty()) return false; if (string.is8Bit()) { const LChar* ptr = string.characters8(); const LChar* end = ptr + string.length(); return genericParseNumberOrPercentage(ptr, end, number); } const UChar* ptr = string.characters16(); const UChar* end = ptr + string.length(); return genericParseNumberOrPercentage(ptr, end, number); }
void TextRun::setText(const String& string) { m_len = string.length(); if (!m_len) { m_data.characters8 = 0; m_is8Bit = true; return; } m_is8Bit = string.is8Bit(); if (m_is8Bit) m_data.characters8 = string.characters8(); else m_data.characters16 = string.characters16(); }
void KURL::setPort(unsigned short port) { if (isDefaultPortForProtocol(port, protocol())) { removePort(); return; } String portString = String::number(port); ASSERT(portString.is8Bit()); url::Replacements<char> replacements; replacements.SetPort(reinterpret_cast<const char*>(portString.characters8()), url::Component(0, portString.length())); replaceComponents(replacements); }
TextRun constructTextRun(const Font& font, const String& string, const ComputedStyle& style, TextDirection direction, TextRunFlags flags) { unsigned length = string.length(); if (!length) return constructTextRunInternal(font, static_cast<const LChar*>(nullptr), length, style, direction, flags); if (string.is8Bit()) return constructTextRunInternal(font, string.characters8(), length, style, direction, flags); return constructTextRunInternal(font, string.characters16(), length, style, direction, flags); }
void SVGStringList::setValueAsString(const String& data, ExceptionState&) { // FIXME: Add more error checking and reporting. m_values.clear(); if (data.isEmpty()) return; if (data.is8Bit()) { const LChar* ptr = data.characters8(); const LChar* end = ptr + data.length(); parseInternal(ptr, end); } else { const UChar* ptr = data.characters16(); const UChar* end = ptr + data.length(); parseInternal(ptr, end); } }
SVGParsingError SVGPointList::setValueAsString(const String& value) { clear(); if (value.isEmpty()) return SVGParseStatus::NoError; if (value.is8Bit()) { const LChar* ptr = value.characters8(); const LChar* end = ptr + value.length(); return parse(ptr, end); } const UChar* ptr = value.characters16(); const UChar* end = ptr + value.length(); return parse(ptr, end); }
static float numericPrefix(const String& keyString, const String& valueString, Document* document, bool* ok = 0) { size_t parsedLength; float value; if (valueString.is8Bit()) value = charactersToFloat(valueString.characters8(), valueString.length(), parsedLength); else value = charactersToFloat(valueString.characters16(), valueString.length(), parsedLength); if (!parsedLength) { reportViewportWarning(document, UnrecognizedViewportArgumentValueError, valueString, keyString); if (ok) *ok = false; return 0; } if (parsedLength < valueString.length()) reportViewportWarning(document, TruncatedViewportArgumentValueError, valueString, keyString); if (ok) *ok = true; return value; }
void SVGPreserveAspectRatio::setValueAsString(const String& string, ExceptionState& exceptionState) { setDefault(); if (string.isEmpty()) return; bool valid = false; if (string.is8Bit()) { const LChar* ptr = string.characters8(); const LChar* end = ptr + string.length(); valid = parseInternal(ptr, end, true); } else { const UChar* ptr = string.characters16(); const UChar* end = ptr + string.length(); valid = parseInternal(ptr, end, true); } if (!valid) { exceptionState.throwDOMException(SyntaxError, "The value provided ('" + string + "') is invalid."); } }
bool SVGFontData::applySVGGlyphSelection(WidthIterator& iterator, GlyphData& glyphData, bool mirror, unsigned currentCharacter, unsigned& advanceLength) const { const TextRun& run = iterator.run(); Vector<SVGGlyph::ArabicForm>& arabicForms = iterator.arabicForms(); ASSERT(run.charactersLength() >= currentCharacter); // Associate text with arabic forms, if needed. String remainingTextInRun; if (run.is8Bit()) { remainingTextInRun = String(run.data8(currentCharacter), run.charactersLength() - currentCharacter); remainingTextInRun = Font::normalizeSpaces(remainingTextInRun.characters8(), remainingTextInRun.length()); } else { remainingTextInRun = String(run.data16(currentCharacter), run.charactersLength() - currentCharacter); remainingTextInRun = Font::normalizeSpaces(remainingTextInRun.characters16(), remainingTextInRun.length()); } if (mirror) remainingTextInRun = createStringWithMirroredCharacters(remainingTextInRun); if (!currentCharacter && arabicForms.isEmpty()) arabicForms = charactersWithArabicForm(remainingTextInRun, mirror); SVGFontFaceElement* svgFontFaceElement = this->svgFontFaceElement(); ASSERT(svgFontFaceElement); SVGFontElement* associatedFontElement = svgFontFaceElement->associatedFontElement(); ASSERT(associatedFontElement); RenderObject* renderObject = 0; if (TextRun::RenderingContext* renderingContext = run.renderingContext()) renderObject = &static_cast<SVGTextRunRenderingContext*>(renderingContext)->renderer(); String language; bool isVerticalText = false; Vector<String> altGlyphNames; if (renderObject) { RenderElement* parentRenderer = renderObject->isRenderElement() ? toRenderElement(renderObject) : renderObject->parent(); ASSERT(parentRenderer); isVerticalText = parentRenderer->style().svgStyle().isVerticalWritingMode(); if (Element* parentRendererElement = parentRenderer->element()) { language = parentRendererElement->getAttribute(XMLNames::langAttr); if (isSVGAltGlyphElement(parentRendererElement)) { SVGAltGlyphElement* altGlyph = toSVGAltGlyphElement(parentRendererElement); if (!altGlyph->hasValidGlyphElements(altGlyphNames)) altGlyphNames.clear(); } } } Vector<SVGGlyph> glyphs; size_t altGlyphNamesSize = altGlyphNames.size(); if (altGlyphNamesSize) { for (size_t index = 0; index < altGlyphNamesSize; ++index) associatedFontElement->collectGlyphsForGlyphName(altGlyphNames[index], glyphs); // Assign the unicodeStringLength now that its known. size_t glyphsSize = glyphs.size(); for (size_t i = 0; i < glyphsSize; ++i) glyphs[i].unicodeStringLength = run.length(); // Do not check alt glyphs for compatibility. Just return the first one. // Later code will fail if we do not do this and the glyph is incompatible. if (glyphsSize) { SVGGlyph& svgGlyph = glyphs[0]; iterator.setLastGlyphName(svgGlyph.glyphName); glyphData.glyph = svgGlyph.tableEntry; advanceLength = svgGlyph.unicodeStringLength; return true; } } else associatedFontElement->collectGlyphsForString(remainingTextInRun, glyphs); size_t glyphsSize = glyphs.size(); for (size_t i = 0; i < glyphsSize; ++i) { SVGGlyph& svgGlyph = glyphs[i]; if (svgGlyph.isPartOfLigature) continue; if (!isCompatibleGlyph(svgGlyph, isVerticalText, language, arabicForms, currentCharacter, currentCharacter + svgGlyph.unicodeStringLength)) continue; iterator.setLastGlyphName(svgGlyph.glyphName); glyphData.glyph = svgGlyph.tableEntry; advanceLength = svgGlyph.unicodeStringLength; return true; } iterator.setLastGlyphName(String()); return false; }