// We handle "parameters" separated by a semicolon, while KURL.cpp does not, // which can lead to different results in some cases. String KURL::lastPathComponent() const { if (!m_isValid) return stringForInvalidComponent(); ASSERT(!m_string.isNull()); // When the output ends in a slash, WebCore has different expectations than // the GoogleURL library. For "/foo/bar/" the library will return the empty // string, but WebCore wants "bar". url::Component path = m_parsed.path; if (path.len > 0 && m_string[path.end() - 1] == '/') path.len--; url::Component file; if (m_string.is8Bit()) url::ExtractFileName(asURLChar8Subtle(m_string), path, &file); else url::ExtractFileName(m_string.characters16(), path, &file); // Bug: https://bugs.webkit.org/show_bug.cgi?id=21015 this function returns // a null string when the path is empty, which we duplicate here. if (!file.is_nonempty()) return String(); return componentString(file); }
bool KURL::isHierarchical() const { if (m_string.isNull() || !m_parsed.scheme.is_nonempty()) return false; return m_string.is8Bit() ? url::IsStandard(asURLChar8Subtle(m_string), m_parsed.scheme) : url::IsStandard(m_string.characters16(), m_parsed.scheme); }
bool protocolIs(const String& url, const char* protocol) { assertProtocolIsGood(protocol); if (url.isNull()) return false; if (url.is8Bit()) return url::FindAndCompareScheme(asURLChar8Subtle(url), url.length(), protocol, 0); return url::FindAndCompareScheme(url.characters16(), url.length(), protocol, 0); }
unsigned KURL::pathAfterLastSlash() const { if (!m_isValid || !m_parsed.path.is_valid()) return m_parsed.CountCharactersBefore(url_parse::Parsed::PATH, false); url_parse::Component filename; if (!m_string.isNull() && m_string.is8Bit()) url_parse::ExtractFileName(asURLChar8Subtle(m_string), m_parsed.path, &filename); else url_parse::ExtractFileName(m_string.characters16(), m_parsed.path, &filename); return filename.begin; }
// Returns 0 when there is no port. // // We treat URL's with out-of-range port numbers as invalid URLs, and they will // be rejected by the canonicalizer. KURL.cpp will allow them in parsing, but // return invalidPortNumber from this port() function, so we mirror that behavior here. unsigned short KURL::port() const { if (!m_isValid || m_parsed.port.len <= 0) return 0; ASSERT(!m_string.isNull()); int port = m_string.is8Bit() ? url::ParsePort(asURLChar8Subtle(m_string), m_parsed.port) : url::ParsePort(m_string.characters16(), m_parsed.port); ASSERT(port != url::PORT_UNSPECIFIED); // Checked port.len <= 0 before. if (port == url::PORT_INVALID || port > maximumValidPortNumber) // Mimic KURL::port() port = invalidPortNumber; return static_cast<unsigned short>(port); }