/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
if (!load) { // To keep the API simple, we fail if the input data buffer if filled. // It's highly unlikely there will ever be such amout of data cumulated // unless a logic fault in the consumer code.
NS_ERROR("IncrementalTokenizer consumer not reading data?"); return NS_ERROR_OUT_OF_MEMORY;
}
if (!mInput.SetLength(remainder + load, fallible)) { return NS_ERROR_OUT_OF_MEMORY;
}
auto buffer = mInput.BeginWriting() + remainder;
uint32_t read;
rv = aInput->Read(buffer, load, &read); if (NS_SUCCEEDED(rv)) { // remainder + load fits the uint32_t size, so must remainder + read.
mInput.SetLength(remainder + read);
aCount -= read;
bool IncrementalTokenizer::Next(Token& aToken) { // Assert we are called only from the consumer callback
MOZ_ASSERT(mConsuming);
if (mPastEof) { returnfalse;
}
nsACString::const_char_iterator next = Parse(aToken);
mPastEof = aToken.Type() == TOKEN_EOF; if (next == mCursor && !mPastEof) { // Not enough input to make a deterministic decision. returnfalse;
}
void IncrementalTokenizer::NeedMoreInput() { // Assert we are called only from the consumer callback
MOZ_ASSERT(mConsuming);
// When the input has been finished, we can't set the flag to prevent // indefinite wait for more input (that will never come)
mNeedMoreInput = !mInputFinished;
}
void IncrementalTokenizer::Rollback() { // Assert we are called only from the consumer callback
MOZ_ASSERT(mConsuming);
mRollback = true;
}
nsresult IncrementalTokenizer::Process() { #ifdef DEBUG // Assert we are not re-entered
MOZ_ASSERT(!mConsuming);
while (NS_SUCCEEDED(rv) && !mPastEof) {
Token token;
nsACString::const_char_iterator next = Parse(token);
mPastEof = token.Type() == TOKEN_EOF; if (next == mCursor && !mPastEof) { // Not enough input to make a deterministic decision. break;
}