// 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); }
String KURL::componentString(const url::Component& component) const { if (!m_isValid || component.len <= 0) return stringForInvalidComponent(); // begin and len are in terms of bytes which do not match // if string() is UTF-16 and input contains non-ASCII characters. // However, the only part in urlString that can contain non-ASCII // characters is 'ref' at the end of the string. In that case, // begin will always match the actual value and len (in terms of // byte) will be longer than what's needed by 'mid'. However, mid // truncates len to avoid go past the end of a string so that we can // get away without doing anything here. return getString().substring(component.begin, component.len); }