예제 #1
0
// StoreVariableString
//------------------------------------------------------------------------------
bool BFFParser::StoreVariableString( const AString & name,
									 const BFFIterator & valueStart, const BFFIterator & valueEnd,
									 const BFFIterator & operatorIter,
									 BFFStackFrame * frame )
{
	// unescape and subsitute embedded variables
	AStackString< 2048 > value;
	if ( PerformVariableSubstitutions( valueStart, valueEnd, value ) == false )
	{
		return false;
	}

	// are we concatenating?
	const BFFVariable * varToConcat = nullptr;
	if ( *operatorIter == BFF_VARIABLE_CONCATENATION )
	{
		// find existing
		varToConcat = BFFStackFrame::GetVar( name, frame );
		if ( varToConcat == nullptr )
		{
			Error::Error_1026_VariableNotFoundForConcatenation( operatorIter, name );
			return false;
		}

		// make sure types are compatible
		if ( varToConcat->IsString() )
		{
			// OK - can concat String to String
			AStackString< 1024 > finalValue( varToConcat->GetString() );
			finalValue += value;

			BFFStackFrame::SetVarString( name, finalValue, frame );
			FLOG_INFO( "Appended '%s' to <String> variable '%s' with result '%s'", value.Get(), name.Get(), finalValue.Get() );
			return true;
		}
		else if ( varToConcat->IsArrayOfStrings() )
		{
			// OK - can concat String to ArrayOfStrings
			Array< AString > finalValues( varToConcat->GetArrayOfStrings().GetSize() + 1, false );
			finalValues = varToConcat->GetArrayOfStrings();
			finalValues.Append( value );

			BFFStackFrame::SetVarArrayOfStrings( name, finalValues, frame );
			FLOG_INFO( "Appended '%s' to <ArrayOfStrings> variable '%s' with result of %i items", value.Get(), name.Get(), finalValues.GetSize() );
			return true;
		}
		else
		{
			Error::Error_1027_CannotConcatenate( operatorIter, name, varToConcat->GetType(), BFFVariable::VAR_STRING );
			return false;
		}
	}

	// handle regular assignment of string
	BFFStackFrame::SetVarString( name, value, frame );
	FLOG_INFO( "Registered <string> variable '%s' with value '%s'", name.Get(), value.Get() );
	return true;
}
예제 #2
0
// StoreVariableString
//------------------------------------------------------------------------------
bool BFFParser::StoreVariableString( const AString & name,
									 const BFFIterator & valueStart, const BFFIterator & valueEnd,
									 const BFFIterator & operatorIter,
									 BFFStackFrame * frame )
{
	// unescape and subsitute embedded variables
	AStackString< 2048 > value;
	if ( PerformVariableSubstitutions( valueStart, valueEnd, value ) == false )
	{
		return false;
	}

	// are we concatenating?
	const BFFVariable * varToConcat = nullptr;
	if ( ( *operatorIter == BFF_VARIABLE_CONCATENATION ) || 
		 ( *operatorIter == BFF_VARIABLE_SUBTRACTION ) )
	{
		// find existing
		varToConcat = BFFStackFrame::GetVar( name, frame );
		if ( varToConcat == nullptr )
		{
			Error::Error_1026_VariableNotFoundForModification( operatorIter, name );
			return false;
		}

		// make sure types are compatible
		if ( varToConcat->IsString() )
		{
			// OK - can concat String to String
			AStackString< 1024 > finalValue( varToConcat->GetString() );
			if ( *operatorIter == BFF_VARIABLE_CONCATENATION )
			{
				finalValue += value;
			}
			else
			{
				finalValue.Replace( value.Get(), "" );
			}

			BFFStackFrame::SetVarString( name, finalValue, frame );
			FLOG_INFO( "%s '%s' %s <String> variable '%s' with result '%s'", 
						( *operatorIter == BFF_VARIABLE_CONCATENATION ) ? "Appending" : "Removing",
						value.Get(), 
						( *operatorIter == BFF_VARIABLE_CONCATENATION ) ? "to" : "from",
						name.Get(), 
						finalValue.Get() );
			return true;
		}
		else if ( varToConcat->IsArrayOfStrings() )
		{
			// OK - can concat String to ArrayOfStrings
			Array< AString > finalValues( varToConcat->GetArrayOfStrings().GetSize() + 1, false );
			if ( *operatorIter == BFF_VARIABLE_CONCATENATION )
			{
				finalValues = varToConcat->GetArrayOfStrings();
				finalValues.Append( value );
			}
			else
			{
				auto end = varToConcat->GetArrayOfStrings().End();
				for ( auto it=varToConcat->GetArrayOfStrings().Begin(); it!=end; ++it )
				{
					if ( *it != value ) // remove equal strings
					{
						finalValues.Append( *it );
					}
				}
			}

			BFFStackFrame::SetVarArrayOfStrings( name, finalValues, frame );
			FLOG_INFO( "%s '%s' %s <ArrayOfStrings> variable '%s' with result of %i items", 
						( *operatorIter == BFF_VARIABLE_CONCATENATION ) ? "Appending" : "Removing",
						value.Get(), 
						( *operatorIter == BFF_VARIABLE_CONCATENATION ) ? "to" : "from",
						name.Get(), 
						finalValues.GetSize() );
			return true;
		}
		else
		{
			Error::Error_1027_CannotModify( operatorIter, name, varToConcat->GetType(), BFFVariable::VAR_STRING );
			return false;
		}
	}

	// handle regular assignment of string
	BFFStackFrame::SetVarString( name, value, frame );
	FLOG_INFO( "Registered <string> variable '%s' with value '%s'", name.Get(), value.Get() );
	return true;
}