/******************************************************************************
 GAddressScanner.cc

	BASE CLASS = public yyFlexLexer

	Copyright © 1997 by Glenn W. Bach.  All rights reserved.
	
	Base code generated by Codemill v0.1.0

 *****************************************************************************/

//Class Header
#include <GAddressScanner.h>

#include <JPtrArray-JString.h>

#include <jAssert.h>

/******************************************************************************
 Constructor

 *****************************************************************************/

GAddressScanner::GAddressScanner
	(
	const JCharacter* 	text, 
	JPtrArray<JString>* list
	)
	:
	GASFlexLexer(),
	itsInputBuffer(text),
	itsBytesRead(0)
{
	itsList = list;
	itsList->SetCompareFunction(JCompareStringsCaseInsensitive);
	itsString = new JString();
	assert(itsString != NULL);
	itsList->InsertSorted(itsString, kTrue);
}

/******************************************************************************
 Destructor

 *****************************************************************************/

GAddressScanner::~GAddressScanner()
{
}

/******************************************************************************
 LexerInput (virtual protected)

 *****************************************************************************/

int
GAddressScanner::LexerInput
	(
	char* flexBuf,
	int   flexBufSize
	)
{
	size_t numCopy;

	assert(flexBuf != NULL);
	assert(flexBufSize > 0);

	int charLeft = itsInputBuffer.GetLength() - itsBytesRead;
	numCopy = (charLeft > flexBufSize) ? flexBufSize : charLeft;

	if (numCopy > 0)
		{
		const JCharacter* buf = itsInputBuffer;
		(void) memcpy(flexBuf, buf + itsBytesRead, numCopy);
		itsBytesRead += numCopy;
		}

	return numCopy;
}
