/******************************************************************************
 PatternBinding.cc

	Copyright © 1997 by Glenn Bach. All rights reserved.

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

#include "PatternBinding.h"
#include <iostream.h>
#include <jAssert.h>

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

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

PatternBinding::PatternBinding
	(
	const JCharacter* 	pattern, 
	const JCharacter* 	action, 
	const JCharacter* 	alternate,
	const JBoolean 		system
	)
	:
	itsPattern(pattern),
	itsPatternWidth(0),
	itsAction(action),
	itsActionWidth(0),
	itsAlternate(alternate),
	itsAlternateWidth(0),
	itsIsSystemBinding(system)
{
}

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

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

PatternBinding::~PatternBinding()
{
}

/******************************************************************************
 CompareSuffixes (static private)

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

JOrderedSetT::CompareResult
PatternBinding::ComparePatterns
	(
	PatternBinding* const & n1,
	PatternBinding* const & n2
	)
{
	const int r = JStringCompare(n1->GetPattern(), n2->GetPattern(), kFalse);

	if (r > 0)
		{
		return JOrderedSetT::kFirstGreaterSecond;
		}
	else if (r < 0)
		{
		return JOrderedSetT::kFirstLessSecond;
		}
	else
		{
		return JOrderedSetT::kFirstEqualSecond;
		}
}

/******************************************************************************
 Stream operators

	The string data is delimited by double quotes:  "this is a string".

	To include double quotes in a string, use \"
	To include a backslash in a string, use \\

	An exception is made if the streams are cin or cout.
	For input, characters are simply read until 'return' is pressed.
	For output, Print() is used.

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

ostream&
operator<<
	(
	ostream&				output,
	const PatternBinding&	binding
	)
{
	output << binding.GetPattern();
	output << binding.GetAction();
	output << binding.GetAlternate();
	output << endl;
	return output;
}
