/******************************************************************************
 JFindLowestPrecedenceOperator (template)

	Returns the location and type of the lowest precedence operator
	that is closest to the end of the string.

	The op array should be ordered from lowest to highest precedence.

	To use this function:
		#define JOperatorInfoType	____
		#define JOperatorType		____
		#include <jFindLPOperator.h>

	Copyright © 1995 by John Lindal. All rights reserved.

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

JBoolean
JFindLowestPrecedenceOperator
	(
	const JCharacter*		expr,
	const JSize				length,

	JOperatorType*			type,
	JSize*					start,
	JSize*					end,

	const JSize				opCount,
	const JOperatorInfoType	op[]
	)
{
	*start = 0;
	for (JSize i=1; i<=opCount; i++)
		{
		JSize offset;
		if (JFindLastOperator(expr, length, op[i-1].name, &offset) && offset > *start)
			{
			*start = offset;
			*end   = offset + strlen(op[i-1].name);
			*type  = op[i-1].type;
			}
		if (i<opCount && *start>0 && op[i].precedence > op[i-1].precedence)
			{
			// Since we have already found an operator and the rest of op[]
			// contains higher precedence operators, we can stop now.

			return kTrue;
			}
		}

	return JConvertToBoolean(*start > 0);
}
