//
//	Copyright © 2005 Nemetschek North America 
//	All Rights Reserved.
//
// Created by Vladislav Stanev

#include "StdAfx.h"
//#include "VWString.h"

using namespace VWFC::Tools;


// --------------------------------------------------------------------------------------------------
/*static*/ void TXStringExt::Tokenize(const TXString& string, TXStringSTLArray& outArray, const char* szTokens, size_t tokensLen)
{
	outArray.clear();

	TXString	currToken;

	size_t	strLen	= string.GetLength();
	for(size_t i=0; i<strLen; i++) {
		char	ch		= string.GetAt( i );

		bool	isToken	= false;
		for(size_t j=0; j<tokensLen; j++) {
			if ( szTokens[j] == ch ) {
				isToken		= true;
				break;
			}
		}

		if ( isToken ) {
			outArray.push_back( currToken );
			currToken.Clear();
		}
		else {
			currToken		+= ch;
		}
	}

	// put the last item if any
	if ( ! currToken.IsEmpty() ) {
		outArray.push_back( currToken );
		currToken.Clear();
	}
}

/*static*/ bool TXStringExt::IsSpace(char c)
{
	return ( ((c) == ' ') || ((c) == '\t') || ((c) == '\n') || ((c) == '\r') );
}

/*static*/ bool TXStringExt::IsDigit(char c)
{
	return ( (((c) >= '0') && ((c) <= '9')) );
}

/*static*/ bool TXStringExt::IsAlpha(char c)
{
	return ( (((c) >= 'a') && ((c) <= 'z')) ) || ( (((c) >= 'A') && ((c) <= 'Z')) );
}

/*static*/ bool TXStringExt::IsDigitOrAlpha(char c)
{
	return TXStringExt::IsDigit( c ) || TXStringExt::IsAlpha( c ) || ((c) == '_');
}

/*static*/ char TXStringExt::ToLower(char c)
{
	return ( (((c) >= 'A') && ((c) <= 'Z')) ? ((c) - 'A' + 'a') : (c) );
}

/*static*/ char TXStringExt::ToUpper(char c)
{
	return ( (((c) >= 'a') && ((c) <= 'z')) ? ((c) - 'a' + 'A') : (c) );
}

/*static*/ char TXStringExt::ToReverseCase(char c)
{
	if ( ( (((c) >= 'a') && ((c) <= 'z')) ) )
		return TXStringExt::ToUpper( c );
	else
		return TXStringExt::ToLower( c );
}

/*static*/ bool TXStringExt::IsDigit(const TXString& string)
{
	size_t	i	= 0;
	if ( i >= string.GetLength() )
		return false;

	if ( string.GetAt(i) == '-' || string.GetAt(i) == '+' || string.GetAt(i) =='.' )
		i++;

	if ( i >= string.GetLength() )
		return false;

	return TXStringExt::IsDigit( string.GetAt(i) );
}
