PRInt32 nsString::RFind( const nsAFlatString& aString, PRInt32 aOffset, PRInt32 aCount ) const { // this method changes the meaning of aOffset and aCount: RFind_ComputeSearchRange(mLength, aString.Length(), aOffset, aCount); PRInt32 result = RFindSubstring(mData + aOffset, aCount, aString.get(), aString.Length(), false); if (result != kNotFound) result += aOffset; return result; }
nsStringKey::nsStringKey(const nsAFlatString& str) : mStr((char16_t*)str.get()), mStrLen(str.Length()), mOwnership(OWN_CLONE) { NS_ASSERTION(mStr, "null string key"); #ifdef DEBUG mKeyType = StringKey; #endif MOZ_COUNT_CTOR(nsStringKey); }
int32_t nsString::RFind( const nsAFlatString& aString, int32_t aOffset, int32_t aCount ) const { // this method changes the meaning of aOffset and aCount: RFind_ComputeSearchRange(mLength, aString.Length(), aOffset, aCount); int32_t result = RFindSubstring(mData + aOffset, aCount, static_cast<const char16_t*>(aString.get()), aString.Length(), false); if (result != kNotFound) result += aOffset; return result; }
nsresult txFormattedCounter::getCounterFor(const nsAFlatString& aToken, PRInt32 aGroupSize, const nsAString& aGroupSeparator, txFormattedCounter*& aCounter) { PRInt32 length = aToken.Length(); NS_ASSERTION(length, "getting counter for empty token"); aCounter = 0; if (length == 1) { PRUnichar ch = aToken.CharAt(0); switch (ch) { case 'i': case 'I': aCounter = new txRomanCounter(ch == 'I'); break; case 'a': case 'A': aCounter = new txAlphaCounter(ch); break; case '1': default: // if we don't recognize the token then use "1" aCounter = new txDecimalCounter(1, aGroupSize, aGroupSeparator); break; } return aCounter ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } // for now, the only multi-char token we support are decimals PRInt32 i; for (i = 0; i < length-1; ++i) { if (aToken.CharAt(i) != '0') break; } if (i == length-1 && aToken.CharAt(i) == '1') { aCounter = new txDecimalCounter(length, aGroupSize, aGroupSeparator); } else { // if we don't recognize the token then use '1' aCounter = new txDecimalCounter(1, aGroupSize, aGroupSeparator); } return aCounter ? NS_OK : NS_ERROR_OUT_OF_MEMORY; }
/** * Returns the document base of the href argument * @return the document base of the given href **/ void URIUtils::getDocumentBase(const nsAFlatString& href, nsAString& dest) { if (href.IsEmpty()) { return; } nsAFlatString::const_char_iterator temp; href.BeginReading(temp); PRUint32 iter = href.Length(); while (iter > 0) { if (temp[--iter] == HREF_PATH_SEP) { dest.Append(Substring(href, 0, iter)); break; } } }
nsresult inCSSValueSearch::SearchStyleValue(const nsAFlatString& aValue, nsIURI* aBaseURL) { if (StringBeginsWith(aValue, NS_LITERAL_STRING("url(")) && StringEndsWith(aValue, NS_LITERAL_STRING(")"))) { const nsASingleFragmentString &url = Substring(aValue, 4, aValue.Length() - 5); // XXXldb Need to do more with |mReturnRelativeURLs|, perhaps? nsCOMPtr<nsIURI> uri; nsresult rv = NS_NewURI(getter_AddRefs(uri), url, nsnull, aBaseURL); NS_ENSURE_SUCCESS(rv, rv); nsCAutoString spec; uri->GetSpec(spec); nsAutoString *result = new NS_ConvertUTF8toUTF16(spec); if (mReturnRelativeURLs) EqualizeURL(result); mResults->AppendElement(result); ++mResultCount; } return NS_OK; }
/** * Implementation of utility functions for parsing URLs. * Just file paths for now. */ void txParsedURL::init(const nsAFlatString& aSpec) { mPath.Truncate(); mName.Truncate(); mRef.Truncate(); PRUint32 specLength = aSpec.Length(); if (!specLength) { return; } const PRUnichar* start = aSpec.get(); const PRUnichar* end = start + specLength; const PRUnichar* c = end - 1; // check for #ref for (; c >= start; --c) { if (*c == '#') { // we could eventually unescape this, too. mRef = Substring(c + 1, end); end = c; --c; if (c == start) { // we're done, return; } break; } } for (c = end - 1; c >= start; --c) { if (*c == '/') { mName = Substring(c + 1, end); mPath = Substring(start, c + 1); return; } } mName = Substring(start, end); }