Reviewed by Brady.
Add reverseFind to String and use it instead of findRev.
Use CString instead of DeprecatedCString in one place.
* html/HTMLFormElement.cpp:
(WebCore::HTMLFormElement::formData):
* ksvg2/svg/SVGURIReference.cpp:
(WebCore::SVGURIReference::getTarget):
* loader/Decoder.cpp:
(WebCore::Decoder::checkForCSSCharset):
* platform/PlatformString.h:
(WebCore::String::reverseFind):
* platform/StringImpl.cpp:
(WebCore::StringImpl::reverseFind):
* platform/StringImpl.h:
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@17346
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
+2006-10-26 Anders Carlsson <acarlsson@apple.com>
+
+ Reviewed by Brady.
+
+ Add reverseFind to String and use it instead of findRev.
+ Use CString instead of DeprecatedCString in one place.
+
+ * html/HTMLFormElement.cpp:
+ (WebCore::HTMLFormElement::formData):
+ * ksvg2/svg/SVGURIReference.cpp:
+ (WebCore::SVGURIReference::getTarget):
+ * loader/Decoder.cpp:
+ (WebCore::Decoder::checkForCSSCharset):
+ * platform/PlatformString.h:
+ (WebCore::String::reverseFind):
+ * platform/StringImpl.cpp:
+ (WebCore::StringImpl::reverseFind):
+ * platform/StringImpl.h:
+
2006-10-26 John Sullivan <sullivan@apple.com>
Reviewed by Darin
// include the filename
if (current->hasLocalName(inputTag) &&
static_cast<HTMLInputElement*>(current)->inputType() == HTMLInputElement::FILE) {
- DeprecatedString path = static_cast<HTMLInputElement*>(current)->value().deprecatedString();
+ String path = static_cast<HTMLInputElement*>(current)->value();
// FIXME: This won't work if the filename includes a " mark,
// or control characters like CR or LF. This also does strange
// things if the filename includes characters you can't encode
// in the website's character set.
hstr += "; filename=\"";
- int start = path.findRev('/') + 1;
+ int start = path.reverseFind('/') + 1;
int length = path.length() - start;
- hstr += encoding.encode(reinterpret_cast<const UChar*>(path.unicode() + start), length, true);
+ hstr += encoding.encode(reinterpret_cast<const UChar*>(path.characters() + start), length, true);
hstr += "\"";
if (!static_cast<HTMLInputElement*>(current)->value().isEmpty()) {
String SVGURIReference::getTarget(const String& url)
{
DeprecatedString urlDeprecated = url.deprecatedString(); // FIXME: Needed until findRev exists for String
- if (urlDeprecated.startsWith("url(")) { // URI References, ie. fill:url(#target)
- unsigned int start = urlDeprecated.find('#') + 1;
- unsigned int end = urlDeprecated.findRev(')');
+ if (url.startsWith("url(")) { // URI References, ie. fill:url(#target)
+ unsigned int start = url.find('#') + 1;
+ unsigned int end = url.reverseFind(')');
- return urlDeprecated.mid(start, end - start);
+ return url.substring(start, end - start);
} else if (url.find('#') > -1) { // format is #target
unsigned int start = url.find('#') + 1;
return url.substring(start, url.length() - start);
if (pos == dataEnd)
return false;
- DeprecatedCString encodingName(dataStart, pos - dataStart + 1);
+ CString encodingName(dataStart, pos - dataStart + 1);
++pos;
if (!skipWhitespace(pos, dataEnd))
{ return m_impl ? m_impl->find(str, start, caseSensitive) : -1; }
int find(const String& str, int start = 0, bool caseSensitive = true) const
{ return m_impl ? m_impl->find(str.impl(), start, caseSensitive) : -1; }
+
+ int reverseFind(UChar c, int start = -1) const
+ { return m_impl ? m_impl->reverseFind(c, start) : -1; }
+ int reverseFind(const String& str, int start = -1, bool caseSensitive = true) const
+ { return m_impl ? m_impl->reverseFind(str.impl(), start, caseSensitive) : -1; }
bool startsWith(const String& s, bool caseSensitive = true) const
{ return m_impl ? m_impl->startsWith(s.impl(), caseSensitive) : s.isEmpty(); }
}
}
+int StringImpl::reverseFind(const UChar c, int index) const
+{
+ if (index >= (int)m_length)
+ return -1;
+
+ if (index < 0)
+ index += m_length;
+ while (1) {
+ if (m_data[index] == c)
+ return index;
+ if (index == 0)
+ return -1;
+ index--;
+ }
+}
+
+int StringImpl::reverseFind(const StringImpl* str, int index, bool caseSensitive) const
+{
+ // FIXME, use the first character algorithm
+ /*
+ See StringImpl::find() for explanations.
+ */
+ ASSERT(str);
+ int lthis = m_length;
+ if (index < 0)
+ index += lthis;
+
+ int lstr = str->m_length;
+ int delta = lthis - lstr;
+ if ( index < 0 || index > lthis || delta < 0 )
+ return -1;
+ if ( index > delta )
+ index = delta;
+
+ const UChar *uthis = m_data;
+ const UChar *ustr = str->m_data;
+ unsigned hthis = 0;
+ unsigned hstr = 0;
+ int i;
+ if (caseSensitive) {
+ for ( i = 0; i < lstr; i++ ) {
+ hthis += uthis[index + i];
+ hstr += ustr[i];
+ }
+ i = index;
+ while (1) {
+ if (hthis == hstr && memcmp(uthis + i, ustr, lstr * sizeof(UChar)) == 0)
+ return i;
+ if (i == 0)
+ return -1;
+ i--;
+ hthis -= uthis[i + lstr];
+ hthis += uthis[i];
+ }
+ } else {
+ for (i = 0; i < lstr; i++) {
+ hthis += tolower(uthis[index + i]);
+ hstr += tolower(ustr[i]);
+ }
+ i = index;
+ while (1) {
+ if (hthis == hstr && equalIgnoringCase(uthis + i, ustr, lstr) )
+ return i;
+ if (i == 0)
+ return -1;
+ i--;
+ hthis -= tolower(uthis[i + lstr]);
+ hthis += tolower(uthis[i]);
+ }
+ }
+
+ // Should never get here.
+ return -1;
+}
+
bool StringImpl::endsWith(const StringImpl* m_data, bool caseSensitive) const
{
ASSERT(m_data);
int find(UChar, int index = 0) const;
int find(const StringImpl*, int index, bool caseSensitive = true) const;
+ int reverseFind(UChar, int index) const;
+ int reverseFind(const StringImpl*, int index, bool caseSensitive = true) const;
+
bool startsWith(const StringImpl* m_data, bool caseSensitive = true) const { return find(m_data, 0, caseSensitive) == 0; }
bool endsWith(const StringImpl*, bool caseSensitive = true) const;