void HTMLAnchorElement::setHost(const String& value) { if (value.isEmpty()) return; KURL url = href(); if (!url.canSetHostOrPort()) return; size_t separator = value.find(':'); if (!separator) return; if (separator == notFound) url.setHostAndPort(value); else { unsigned portEnd; unsigned port = parsePortFromStringPosition(value, separator + 1, portEnd); if (!port) { // http://dev.w3.org/html5/spec/infrastructure.html#url-decomposition-idl-attributes // specifically goes against RFC 3986 (p3.2) and // requires setting the port to "0" if it is set to empty string. url.setHostAndPort(value.substring(0, separator + 1) + "0"); } else { if (isDefaultPortForProtocol(port, url.protocol())) url.setHostAndPort(value.substring(0, separator)); else url.setHostAndPort(value.substring(0, portEnd)); } } setHref(url.string()); }
void KURL::setHostAndPort(const String& hostAndPort) { size_t separator = hostAndPort.find(':'); if (!separator) return; if (separator == kNotFound) { url::Replacements<char> replacements; StringUTF8Adaptor hostUTF8(hostAndPort); replacements.SetHost(charactersOrEmpty(hostUTF8), url::Component(0, hostUTF8.length())); replaceComponents(replacements); return; } String host = hostAndPort.substring(0, separator); String port = parsePortFromStringPosition(hostAndPort, separator + 1); StringUTF8Adaptor hostUTF8(host); StringUTF8Adaptor portUTF8(port); url::Replacements<char> replacements; replacements.SetHost(charactersOrEmpty(hostUTF8), url::Component(0, hostUTF8.length())); replacements.SetPort(charactersOrEmpty(portUTF8), url::Component(0, portUTF8.length())); replaceComponents(replacements); }
void KURL::setPort(const String& port) { String parsedPort = parsePortFromStringPosition(port, 0); setPort(parsedPort.toUInt()); }