scandsp/src/dspparser.cxx
// ===========================================================================
// Evaluate an expression within an If or Elsif.
// This function probably omits much of what Microsoft supports,
// but it has worked fine in many, many cases.
// Returns a simple bool.
//
Evaluate an expression within an If or Elsif.
This function probably omits much of what Microsoft supports,
but it has worked fine in many, many cases.
Returns a simple bool.
Evaluate an expression within an If or Elsif . This function probably omits much of what Microsoft supports but it has worked fine in many many cases . Returns a simple bool .
bool DSPParser::eval(const list<Token> &toks)
{
    string left;
    string right;
    string junk;
    int eq_count = 0;
    bool result = false;
    bool have_whitespace = false;
    list<Token>::const_iterator it;
    for (it = toks.begin(); it != toks.end(); ++it) {
	const Token &tok = *it;
	if (tok.kind() == Token::Delimiter && tok.string() == "==") {
	    eq_count += 1;
	}
	else {
	    if (tok.kind() == Token::Whitespace) {
		have_whitespace = true;
	    }
	    else if (tok.kind() != Token::NoKind) {
		string &appendee = eq_count == 0 ? left : eq_count == 1 ? right : junk;
		if (have_whitespace) {
		    if (appendee.length() > 0) {
			appendee.append(" ");
		    }
		    have_whitespace = false;
		}
		appendee.append(tok.string());
	    }
	}
    }
    if (eq_count == 1) {
	string left_value;
	eval(left_value, left);
        string stripped_left_value;
	charStrip('"', stripped_left_value, left_value);
	string right_value;
	eval(right_value, right);
        string stripped_right_value;
	charStrip('"', stripped_right_value, right_value);
	cvttoupper(stripped_left_value);
	cvttoupper(stripped_right_value);
	result = (stripped_left_value == stripped_right_value);
    }
    return result;
}
bool DSPParser :: eval ( const list < Token > & toks ) { string left ; string right ; string junk ; int eq_count = 0 ; bool result = false ; bool have_whitespace = false ; list < Token > :: const_iterator it ; for ( it = toks . begin ( ) ; it != toks . end ( ) ; ++ it ) { const Token & tok = * it ; if ( tok . kind ( ) == Token :: Delimiter && tok . string ( ) == " " ) { eq_count += 1 ; } else { if ( tok . kind ( ) == Token :: Whitespace ) { have_whitespace = true ; } else if ( tok . kind ( ) != Token :: NoKind ) { string & appendee = eq_count == 0 ? left : eq_count == 1 ? right : junk ; if ( have_whitespace ) { if ( appendee . length ( ) > 0 ) { appendee . append ( " " ) ; } have_whitespace = false ; } appendee . append ( tok . string ( ) ) ; } } } if ( eq_count == 1 ) { string left_value ; eval ( left_value , left ) ; string stripped_left_value ; charStrip ( ' ' , stripped_left_value , left_value ) ; string right_value ; eval ( right_value , right ) ; string stripped_right_value ; charStrip ( ' ' , stripped_right_value , right_value ) ; cvttoupper ( stripped_left_value ) ; cvttoupper ( stripped_right_value ) ; result = ( stripped_left_value == stripped_right_value ) ; } return result ; }
Evaluate an expression within an If or Elsif.
Evaluate an expression within an If or Elsif .
// Compare, ignoring case.