//-----------------------------------------------------------------------------------------------
// IntRange.cpp
//
#include "GypsyPrecompiledHeader.hpp"

//-----------------------------------------------------------------------------------------------
#include "Engine/Core/IntRange.hpp"
#include "Engine/Core/ErrorWarningAssert.hpp"
#include <stdlib.h>


//-----------------------------------------------------------------------------------------------
STATIC const IntRange IntRange::kZero		( 0, 0 );
STATIC const IntRange IntRange::kOne		( 1, 1 );
STATIC const IntRange IntRange::kZeroOrOne	( 0, 1 );


//-----------------------------------------------------------------------------------------------
IntRange::IntRange( const char* asText )
	: min( 0 )
	, max( 0 )
{
	SetFromText( asText );
}


//-----------------------------------------------------------------------------------------------
void IntRange::SetFromText( const char* asText )
{
	const int kMaxBufferLength = 1024;
	char writeBuffer[ kMaxBufferLength ];
	const char* readScan = asText;
	char* writeScan = writeBuffer;
	char* startOfSecondValue = writeBuffer;
	char* endOfTempBuffer = &writeBuffer[ kMaxBufferLength - 1 ];
	
	while( *readScan != '\0' && writeScan != endOfTempBuffer )
	{
		if( *readScan == ',' )
		{
			*writeScan = '\0';
			startOfSecondValue = writeScan + 1;
		}
		else
		{
			*writeScan = *readScan;
		}

		++ readScan;
		++ writeScan;
	}

	*writeScan = '\0';
	min = atoi( writeBuffer );
	max = atoi( startOfSecondValue );
}

