NS_IMETHODIMP nsStringInputStream::ReadSegments(nsWriteSegmentFun aWriter, void* aClosure, uint32_t aCount, uint32_t* aResult) { NS_ASSERTION(aResult, "null ptr"); NS_ASSERTION(Length() >= mOffset, "bad stream state"); if (Closed()) { return NS_BASE_STREAM_CLOSED; } // We may be at end-of-file uint32_t maxCount = LengthRemaining(); if (maxCount == 0) { *aResult = 0; return NS_OK; } if (aCount > maxCount) { aCount = maxCount; } nsresult rv = aWriter(this, aClosure, mData.BeginReading() + mOffset, 0, aCount, aResult); if (NS_SUCCEEDED(rv)) { NS_ASSERTION(*aResult <= aCount, "writer should not write more than we asked it to write"); mOffset += *aResult; } // errors returned from the writer end here! return NS_OK; }
/* static */ bool MatchAutoCompleteFunction::findBeginning(const nsDependentCSubstring &aToken, const nsACString &aSourceString) { NS_PRECONDITION(!aToken.IsEmpty(), "Don't search for an empty token!"); // We can't use StringBeginsWith here, unfortunately. Although it will // happily take a case-insensitive UTF8 comparator, it eventually calls // nsACString::Equals, which checks that the two strings contain the same // number of bytes before calling the comparator. This is clearly not what // we want. const_char_iterator tokenStart(aToken.BeginReading()), tokenEnd(aToken.EndReading()), sourceStart(aSourceString.BeginReading()), sourceEnd(aSourceString.EndReading()); PRBool dummy; while (sourceStart < sourceEnd && CaseInsensitiveUTF8CharsEqual(sourceStart, tokenStart, sourceEnd, tokenEnd, &sourceStart, &tokenStart, &dummy)) { // We found the token! if (tokenStart >= tokenEnd) { return true; } } // We don't need to check CaseInsensitiveUTF8CharsEqual's error condition // (stored in |dummy|), since the function will return false if it // encounters an error. return false; }
static void AppendPrefixToMap(PrefixStringMap& prefixes, nsDependentCSubstring& prefix) { if (!prefix.Length()) { return; } nsCString* prefixString = prefixes.LookupOrAdd(prefix.Length()); prefixString->Append(prefix.BeginReading(), prefix.Length()); }