Exemple #1
0
// FindReplaceNoCase	- Find a substring and replace with another
//			  Does case insensitive search
// Returns		- Number of instances replaced
// lpszSub		- Substring to look for
// lpszReplaceWith	- Substring to replace with
// bGlobal		- Flag to indicate whether all occurances
//			  should be replaced
int CStringEx::FindReplaceNoCase( LPCTSTR lpszSub, LPCTSTR lpszReplaceWith, 
					 BOOL bGlobal /*= TRUE*/ )
{
	CStringEx sLowerThis = *this;
	sLowerThis.MakeLower();

	CStringEx sLowerSub = lpszSub;
	sLowerSub.MakeLower();

	int iReplaced = 0;

	// find first matching substring
	LPTSTR lpsz;
	
	int pos = 0, offset = 0;
	int lenSub = lstrlen( lpszSub );
	int lenReplaceWith = lstrlen( lpszReplaceWith );
	while( (lpsz = _tcsstr(sLowerThis.m_pchData + pos, sLowerSub.m_pchData)) 
!= NULL )
	{
		pos = (int)(lpsz - sLowerThis.m_pchData);
		Replace( pos+offset, lenSub, lpszReplaceWith );
		offset += lenReplaceWith - lenSub;
		pos += lenSub;
		iReplaced++;
		if( !bGlobal ) break;
	}

	return iReplaced;
}
CStringEx CTypeUnitIntSigned::CalculateResult( const CStringEx _sxbasevalue, const CStringEx _sxvalue ) const	
{
	nlassert( !_sxbasevalue.empty() );
	if( _sxvalue.empty() )
		return( _sxbasevalue );

	std::vector< std::pair< CStringEx, CStringEx > > modificationValues;
	CStringEx value( _sxvalue );
	value.purge();
	while( value[0] == '<' )
	{
		unsigned int pos = value.find( '>' );
		if( pos == -1 )
			break;
		CStringEx sxoperateur = value.get_mid( 1, 1 );
		CStringEx sxoperande = value.get_mid( 2, pos-2);
		value.right( value.size()-pos-1 );
		modificationValues.push_back( std::make_pair( sxoperateur, sxoperande ) );
	}
	if( modificationValues.size() )
	{
		sint64 ir = atoiInt64( _sxbasevalue.c_str() );
		for( std::vector< std::pair< CStringEx, CStringEx > >::iterator it = modificationValues.begin(); it != modificationValues.end(); ++it )
		{
			sint64 ivalue = atoiInt64( it->second.c_str() );
			if( it->first == "+" )
				ir += ivalue;
			else if( it->first == "*" )
					ir *= ivalue;
				else if( it->first == "-" )
						ir -= ivalue;
					else if( it->first == "/" )
							ir /= ivalue;   
						else if( it->first == "^" )
								ir = (sint64)( pow( (double)(ir), (double)(ivalue) ) );   
		}
		if( ir < ilowlimit )
			ir = ilowlimit;
		if( ir > ihighlimit )
			ir = ihighlimit;
		char pc[256];
		itoaInt64( ir, pc, 10 );
		return( CStringEx( pc ) );
	}
	else
	{
		sint64 ivalue = atoiInt64( _sxvalue.c_str() );
		if( ivalue < ilowlimit )
			ivalue = ilowlimit;
		if( ivalue > ihighlimit )
			ivalue = ihighlimit;
		char pc[256];
		itoaInt64( ivalue, pc, 10 );
		return( CStringEx( pc ) );
	}

	return( Format( _sxvalue ) );
}
Exemple #3
0
// FindNoCase	- Case insensitive find
// Returns	- A zero-based index
// lpszSub	- Substring to search for
// startpos 	- Position to start looking from
int CStringEx::FindNoCase( LPCTSTR lpszSub, int startpos /*= 0*/ ) const
{
	CStringEx sLowerThis = *this;
	sLowerThis.MakeLower();

	CStringEx sLowerSub = lpszSub;
	sLowerSub.MakeLower();

	return sLowerThis.Find( sLowerSub, startpos );
}
/*									
CStringEx CTypeUnitDouble::CalculateResult( const CStringEx _sxbasevalue, const CStringEx _sxvalue ) const	
{
	nlassert( !_sxbasevalue.empty() );
	if( _sxvalue.empty() )
		return( _sxbasevalue );
	return( Format( _sxvalue ) );
}
*/
CStringEx CTypeUnitDouble::CalculateResult( const CStringEx _sxbasevalue, const CStringEx _sxvalue ) const	
{
	nlassert( !_sxbasevalue.empty() );
	if( _sxvalue.empty() )
		return( _sxbasevalue );

	std::vector< std::pair< CStringEx, CStringEx > > modificationValues;
	CStringEx value( _sxvalue );
	value.purge();
	while( value[0] == '<' )
	{
		std::string::size_type pos = value.find( '>' );
		if( pos == std::string::npos )
			break;
		CStringEx sxoperateur = value.get_mid( 1, 1 );
		CStringEx sxoperande = value.get_mid( 2, (int)pos-2);
		value.right( (int)(value.size()-pos-1) );
		modificationValues.push_back( std::make_pair( sxoperateur, sxoperande ) );
	}
	if( modificationValues.size() )
	{
		double dr = atof( _sxbasevalue.c_str() );
		for( std::vector< std::pair< CStringEx, CStringEx > >::iterator it = modificationValues.begin(); it != modificationValues.end(); ++it )
		{
			double dvalue = atof( it->second.c_str() );
			if( it->first == "+" )
				dr += dvalue;
			else if( it->first == "*" )
					dr *= dvalue;
				else if( it->first == "-" )
						dr -= dvalue;
					else if( it->first == "/" )
							dr /= dvalue;   
						else if( it->first == "^" )
								dr = pow( dr, dvalue );   
		}
		if( dr < dlowlimit )
			dr = dlowlimit;
		if( dr > dhighlimit )
			dr = dhighlimit;
		return( FormatDouble( dr ) );
	}
	else
	{
		double dvalue = atof( _sxvalue.c_str() );
		if( dvalue < dlowlimit )
			dvalue = dlowlimit;
		if( dvalue > dhighlimit )
			dvalue = dhighlimit;
		return( FormatDouble( dvalue ) );
	}

	return( Format( _sxvalue ) );
}
Exemple #5
0
bool  CStringEx::operator < ( const CStringEx& s ) const 
{
	const_iterator it = begin();
	const_iterator is = s.begin();
	while( ( it != end() )&&( is != s.end() ) )
	{
		if( *it != *is )
			return( *it < *is );
		it++;
		is++;
	}
	return( is != s.end() );
}
CStringEx CTypeUnitIntSigned::Format( const CStringEx _sxvalue ) const
{
	if( _sxvalue.empty() )
		return( sxdefaultvalue );

	std::vector< std::pair< CStringEx, CStringEx > > modificationValues;
	CStringEx value( _sxvalue );
	value.purge();
	while( value[0] == '<' )
	{
		unsigned int pos = value.find( '>' );
		if( pos == -1 )
			break;
		CStringEx sxoperateur = value.get_mid( 1, 1 );
		CStringEx sxoperande = value.get_mid( 2, pos-2);
		value.right( value.size()-pos-1 );
		modificationValues.push_back( std::make_pair( sxoperateur, sxoperande ) );
	}
	if( modificationValues.size() )
	{
		CStringEx sxr;
		for( std::vector< std::pair< CStringEx, CStringEx > >::iterator it = modificationValues.begin(); it != modificationValues.end(); ++it )
		{
			sxr += CStringEx( "<" );
			sxr += it->first;
			sxr += it->second;
			sxr += CStringEx( ">" );
		}
		return( sxr );
	}
	else
	{
		sint64 ivalue = atoiInt64( _sxvalue.c_str() );
		if( ivalue < ilowlimit )
			ivalue = ilowlimit;
		if( ivalue > ihighlimit )
			ivalue = ihighlimit;

		char pc[256];
		itoaInt64( ivalue, pc, 10 );
		return( CStringEx( pc ) );
	}
}
/*
CStringEx CTypeUnitDouble::Format( const CStringEx _sxvalue ) const
{
	if( _sxvalue.empty() )
		return( sxdefaultvalue );

	double dvalue = atof( _sxvalue.c_str() );
	if( dvalue < dlowlimit )
		dvalue = dlowlimit;
	if( dvalue > dhighlimit )
		dvalue = dhighlimit;
	return( FormatDouble( dvalue ) );
}
*/
CStringEx CTypeUnitDouble::Format( const CStringEx _sxvalue ) const
{
	if( _sxvalue.empty() )
		return( sxdefaultvalue );

	std::vector< std::pair< CStringEx, CStringEx > > modificationValues;
	CStringEx value( _sxvalue );
	value.purge();
	while( value[0] == '<' )
	{
		std::string::size_type pos = value.find( '>' );
		if( pos == std::string::npos )
			break;
		CStringEx sxoperateur = value.get_mid( 1, 1 );
		CStringEx sxoperande = value.get_mid( 2, (int)pos-2);
		value.right( (int)(value.size()-pos-1) );
		modificationValues.push_back( std::make_pair( sxoperateur, sxoperande ) );
	}
	if( modificationValues.size() )
	{
		CStringEx sxr;
		for( std::vector< std::pair< CStringEx, CStringEx > >::iterator it = modificationValues.begin(); it != modificationValues.end(); ++it )
		{
			sxr += CStringEx( "<" );
			sxr += it->first;
			sxr += it->second;
			sxr += CStringEx( ">" );
		}
		return( sxr );
	}
	else
	{
		double dvalue = atof( _sxvalue.c_str() );
		if( dvalue < dlowlimit )
			dvalue = dlowlimit;
		if( dvalue > dhighlimit )
			dvalue = dhighlimit;
		return( FormatDouble( dvalue ) );
	}
}