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::setHost(const String& host) { StringUTF8Adaptor hostUTF8(host); url::Replacements<char> replacements; replacements.SetHost(charactersOrEmpty(hostUTF8), url::Component(0, hostUTF8.length())); replaceComponents(replacements); }
bool KURL::setProtocol(const String& protocol) { // Firefox and IE remove everything after the first ':'. int separatorPosition = protocol.find(':'); String newProtocol = protocol.substring(0, separatorPosition); StringUTF8Adaptor newProtocolUTF8(newProtocol); // If KURL is given an invalid scheme, it returns failure without modifying // the URL at all. This is in contrast to most other setters which modify // the URL and set "m_isValid." url::RawCanonOutputT<char> canonProtocol; url::Component protocolComponent; if (!url::CanonicalizeScheme(newProtocolUTF8.data(), url::Component(0, newProtocolUTF8.length()), &canonProtocol, &protocolComponent) || !protocolComponent.is_nonempty()) return false; url::Replacements<char> replacements; replacements.SetScheme(charactersOrEmpty(newProtocolUTF8), url::Component(0, newProtocolUTF8.length())); replaceComponents(replacements); // isValid could be false but we still return true here. This is because // WebCore or JS scripts can build up a URL by setting individual // components, and a JS exception is based on the return value of this // function. We want to throw the exception and stop the script only when // its trying to set a bad protocol, and not when it maybe just hasn't // finished building up its final scheme. return true; }
void KURL::setPath(const String& path) { // Empty paths will be canonicalized to "/", so we don't have to worry // about calling ClearPath(). StringUTF8Adaptor pathUTF8(path); url::Replacements<char> replacements; replacements.SetPath(charactersOrEmpty(pathUTF8), url::Component(0, pathUTF8.length())); replaceComponents(replacements); }
void KURL::setQuery(const String& query) { StringUTF8Adaptor queryUTF8(query); url::Replacements<char> replacements; if (query.isNull()) { // KURL.cpp sets to null to clear any query. replacements.ClearQuery(); } else if (query.length() > 0 && query[0] == '?') { // WebCore expects the query string to begin with a question mark, but // GoogleURL doesn't. So we trim off the question mark when setting. replacements.SetQuery(charactersOrEmpty(queryUTF8), url::Component(1, queryUTF8.length() - 1)); } else { // When set with the empty string or something that doesn't begin with // a question mark, KURL.cpp will add a question mark for you. The only // way this isn't compatible is if you call this function with an empty // string. KURL.cpp will leave a '?' with nothing following it in the // URL, whereas we'll clear it. // FIXME We should eliminate this difference. replacements.SetQuery(charactersOrEmpty(queryUTF8), url::Component(0, queryUTF8.length())); } replaceComponents(replacements); }
void KURL::setPass(const String& pass) { // This function is commonly called to clear the password, which we // normally don't have, so we optimize this case. if (pass.isEmpty() && !m_parsed.password.is_valid()) return; // The canonicalizer will clear any passwords that are empty, so we // don't have to explicitly call ClearUsername() here. StringUTF8Adaptor passUTF8(pass); url::Replacements<char> replacements; replacements.SetPassword(charactersOrEmpty(passUTF8), url::Component(0, passUTF8.length())); replaceComponents(replacements); }
void KURL::setUser(const String& user) { // This function is commonly called to clear the username, which we // normally don't have, so we optimize this case. if (user.isEmpty() && !m_parsed.username.is_valid()) return; // The canonicalizer will clear any usernames that are empty, so we // don't have to explicitly call ClearUsername() here. StringUTF8Adaptor userUTF8(user); url_canon::Replacements<char> replacements; replacements.SetUsername(charactersOrEmpty(userUTF8), url_parse::Component(0, userUTF8.length())); replaceComponents(replacements); }
void KURL::setHostAndPort(const String& hostAndPort) { String host = hostAndPort; String port; int hostEnd = hostAndPort.find(":"); if (hostEnd != -1) { host = hostAndPort.left(hostEnd); port = hostAndPort.substring(hostEnd + 1); } StringUTF8Adaptor hostUTF8(host); StringUTF8Adaptor portUTF8(port); url_canon::Replacements<char> replacements; // Host can't be removed, so we always set. replacements.SetHost(charactersOrEmpty(hostUTF8), url_parse::Component(0, hostUTF8.length())); if (!portUTF8.length()) // Port may be removed, so we support clearing. replacements.ClearPort(); else replacements.SetPort(charactersOrEmpty(portUTF8), url_parse::Component(0, portUTF8.length())); replaceComponents(replacements); }
void KURL::setFragmentIdentifier(const String& fragment) { // This function is commonly called to clear the ref, which we // normally don't have, so we optimize this case. if (fragment.isNull() && !m_parsed.ref.is_valid()) return; StringUTF8Adaptor fragmentUTF8(fragment); url::Replacements<char> replacements; if (fragment.isNull()) replacements.ClearRef(); else replacements.SetRef(charactersOrEmpty(fragmentUTF8), url::Component(0, fragmentUTF8.length())); replaceComponents(replacements); }