static inline void transformTextStringToXHTMLDocumentString(String& text) { // Modify the output so that it is a well-formed XHTML document with a <pre> tag enclosing the text. text.replaceWithLiteral('&', "&"); text.replaceWithLiteral('<', "<"); text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n" "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" "<head><title/></head>\n" "<body>\n" "<pre>" + text + "</pre>\n" "</body>\n" "</html>\n"; }
void InlineTextBox::showBox(int printedCharacters) const { String value = text(); value.replaceWithLiteral('\\', "\\\\"); value.replaceWithLiteral('\n', "\\n"); printedCharacters += fprintf(stderr, "%s %p", boxName(), this); for (; printedCharacters < showTreeCharacterOffset; printedCharacters++) fputc(' ', stderr); const LineLayoutText obj = lineLayoutItem(); printedCharacters = fprintf(stderr, "\t%s %p", obj.name(), obj.debugPointer()); const int layoutObjectCharacterOffset = 75; for (; printedCharacters < layoutObjectCharacterOffset; printedCharacters++) fputc(' ', stderr); fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().data()); }
void MarkupAccumulator::appendQuotedURLAttributeValue(StringBuilder& result, const Element& element, const Attribute& attribute) { ASSERT(element.isURLAttribute(attribute)); const String resolvedURLString = resolveURLIfNeeded(element, attribute.value()); UChar quoteChar = '"'; String strippedURLString = resolvedURLString.stripWhiteSpace(); if (protocolIsJavaScript(strippedURLString)) { // minimal escaping for javascript urls if (strippedURLString.contains('"')) { if (strippedURLString.contains('\'')) strippedURLString.replaceWithLiteral('"', """); else quoteChar = '\''; } result.append(quoteChar); result.append(strippedURLString); result.append(quoteChar); return; } // FIXME: This does not fully match other browsers. Firefox percent-escapes non-ASCII characters for innerHTML. result.append(quoteChar); appendAttributeValue(result, resolvedURLString, false); result.append(quoteChar); }
void HTMLAnchorElement::setSearch(const String& value) { KURL url = href(); String newSearch = (value[0] == '?') ? value.substring(1) : value; // Make sure that '#' in the query does not leak to the hash. url.setQuery(newSearch.replaceWithLiteral('#', "%23")); setHref(url.string()); }
static void appendMailtoPostFormDataToURL(URL& url, const FormData& data, const String& encodingType) { String body = data.flattenToString(); if (equalIgnoringCase(encodingType, "text/plain")) { // Convention seems to be to decode, and s/&/\r\n/. Also, spaces are encoded as %20. body = decodeURLEscapeSequences(body.replaceWithLiteral('&', "\r\n").replace('+', ' ') + "\r\n"); } Vector<char> bodyData; bodyData.append("body=", 5); FormDataBuilder::encodeStringAsFormData(bodyData, body.utf8()); body = String(bodyData.data(), bodyData.size()).replaceWithLiteral('+', "%20"); String query = url.query(); if (!query.isEmpty()) query.append('&'); query.append(body); url.setQuery(query); }
TEST(WTF, StringReplaceWithLiteral) { // Cases for 8Bit source. String testString = "1224"; ASSERT_TRUE(testString.is8Bit()); testString.replaceWithLiteral('2', ""); ASSERT_STREQ("14", testString.utf8().data()); testString = "1224"; ASSERT_TRUE(testString.is8Bit()); testString.replaceWithLiteral('2', "3"); ASSERT_STREQ("1334", testString.utf8().data()); testString = "1224"; ASSERT_TRUE(testString.is8Bit()); testString.replaceWithLiteral('2', "555"); ASSERT_STREQ("15555554", testString.utf8().data()); testString = "1224"; ASSERT_TRUE(testString.is8Bit()); testString.replaceWithLiteral('3', "NotFound"); ASSERT_STREQ("1224", testString.utf8().data()); // Cases for 16Bit source. testString = String::fromUTF8("résumé"); ASSERT_FALSE(testString.is8Bit()); testString.replaceWithLiteral(UChar(0x00E9 /*U+00E9 is 'é'*/), "e"); ASSERT_STREQ("resume", testString.utf8().data()); testString = String::fromUTF8("résumé"); ASSERT_FALSE(testString.is8Bit()); testString.replaceWithLiteral(UChar(0x00E9 /*U+00E9 is 'é'*/), ""); ASSERT_STREQ("rsum", testString.utf8().data()); testString = String::fromUTF8("résumé"); ASSERT_FALSE(testString.is8Bit()); testString.replaceWithLiteral('3', "NotFound"); ASSERT_STREQ("résumé", testString.utf8().data()); }