/** * Use this constructor if you want i/o to be stream based. * * @update gess 5/12/98 * @param aStream -- * @param assumeOwnership -- * @param aFilename -- * @return */ nsScanner::nsScanner(const nsAString& aFilename, nsIInputStream* aStream, const nsACString& aCharset, PRInt32 aSource) : mFilename(aFilename), mParser(nsnull) { MOZ_COUNT_CTOR(nsScanner); mSlidingBuffer = nsnull; // XXX This is a big hack. We need to initialize the iterators to something. // What matters is that mCurrentPosition == mEndPosition, so that our methods // believe that we are at EOF (see bug 182067). We null out mCurrentPosition // so that we have some hope of catching null pointer dereferences associated // with this hack. --darin memset(&mCurrentPosition, 0, sizeof(mCurrentPosition)); mMarkPosition = mCurrentPosition; mEndPosition = mCurrentPosition; mIncremental = PR_FALSE; mFirstNonWhitespacePosition = -1; mCountRemaining = 0; mTotalRead=0; mInputStream=aStream; mUnicodeDecoder = 0; mCharsetSource = kCharsetUninitialized; SetDocumentCharset(aCharset, aSource); }
/** * Use this constructor if you want i/o to be based on strings * the scanner receives. If you pass a null filename, you * can still provide data to the scanner via append. * * @update gess 5/12/98 * @param aFilename -- * @return */ nsScanner::nsScanner(nsString& aFilename,bool aCreateStream, const nsACString& aCharset, PRInt32 aSource) : mFilename(aFilename) { MOZ_COUNT_CTOR(nsScanner); NS_ASSERTION(!aCreateStream, "This is always true."); mSlidingBuffer = nsnull; // XXX This is a big hack. We need to initialize the iterators to something. // What matters is that mCurrentPosition == mEndPosition, so that our methods // believe that we are at EOF (see bug 182067). We null out mCurrentPosition // so that we have some hope of catching null pointer dereferences associated // with this hack. --darin memset(&mCurrentPosition, 0, sizeof(mCurrentPosition)); mMarkPosition = mCurrentPosition; mEndPosition = mCurrentPosition; mIncremental = true; mFirstNonWhitespacePosition = -1; mCountRemaining = 0; mUnicodeDecoder = 0; mCharsetSource = kCharsetUninitialized; mHasInvalidCharacter = false; mReplacementCharacter = PRUnichar(0x0); SetDocumentCharset(aCharset, aSource); }
nsHtml5Parser::SetDocumentCharset(const nsACString& aCharset, PRInt32 aCharsetSource) { NS_PRECONDITION(!mExecutor->HasStarted(), "Document charset set too late."); NS_PRECONDITION(mStreamParser, "Setting charset on a script-only parser."); mStreamParser->SetDocumentCharset(aCharset, aCharsetSource); mExecutor->SetDocumentCharsetAndSource((nsACString&)aCharset, aCharsetSource); }
nsHtml5Parser::SetDocumentCharset(const nsACString& aCharset, PRInt32 aCharsetSource) { NS_PRECONDITION(!mExecutor->HasStarted(), "Document charset set too late."); NS_PRECONDITION(mStreamParser, "Setting charset on a script-only parser."); nsCAutoString trimmed; trimmed.Assign(aCharset); trimmed.Trim(" \t\r\n\f"); mStreamParser->SetDocumentCharset(trimmed, aCharsetSource); mExecutor->SetDocumentCharsetAndSource(trimmed, aCharsetSource); }
/** * Use this constructor if you want i/o to be based on * a single string you hand in during construction. * This short cut was added for Javascript. * * @update gess 5/12/98 * @param aMode represents the parser mode (nav, other) * @return */ nsScanner::nsScanner(const nsAString& anHTMLString, const nsACString& aCharset, PRInt32 aSource) : mParser(nsnull) { MOZ_COUNT_CTOR(nsScanner); mTotalRead = anHTMLString.Length(); mSlidingBuffer = nsnull; mCountRemaining = 0; mFirstNonWhitespacePosition = -1; AppendToBuffer(anHTMLString); mSlidingBuffer->BeginReading(mCurrentPosition); mMarkPosition = mCurrentPosition; mIncremental = PR_FALSE; mUnicodeDecoder = 0; mCharsetSource = kCharsetUninitialized; SetDocumentCharset(aCharset, aSource); }
/** * Use this constructor if you want i/o to be based on * a single string you hand in during construction. * This short cut was added for Javascript. * * @update gess 5/12/98 * @param aMode represents the parser mode (nav, other) * @return */ nsScanner::nsScanner(const nsAString& anHTMLString, const nsACString& aCharset, PRInt32 aSource) : mParser(nsnull) { MOZ_COUNT_CTOR(nsScanner); mSlidingBuffer = nsnull; mCountRemaining = 0; mFirstNonWhitespacePosition = -1; if (AppendToBuffer(anHTMLString)) { mTotalRead = anHTMLString.Length(); mSlidingBuffer->BeginReading(mCurrentPosition); } else { mTotalRead = 0; /* XXX see hack below, re: bug 182067 */ memset(&mCurrentPosition, 0, sizeof(mCurrentPosition)); mEndPosition = mCurrentPosition; } mMarkPosition = mCurrentPosition; mIncremental = PR_FALSE; mUnicodeDecoder = 0; mCharsetSource = kCharsetUninitialized; SetDocumentCharset(aCharset, aSource); }