matchesValueSpecifier function

bool matchesValueSpecifier(
  1. String valueSpecifier,
  2. Map<String, dynamic>? valueByNameMap
)

Implementation

bool matchesValueSpecifier(
    String valueSpecifier,
    Map<String, dynamic>? valueByNameMap
    )
{
    if ( valueByNameMap != null )
    {
        var match = valueExpression.firstMatch( valueSpecifier );

        if ( match != null )
        {
            String valueName = match.group(1)!;
            String operator = match.group(2)!;
            dynamic otherValue = match.group(3)!;

            if ( valueByNameMap.containsKey( valueName ) )
            {
                dynamic value = valueByNameMap[ valueName ];

                if ( value is num )
                {
                    otherValue = num.parse( otherValue );
                }

                if ( ( operator == '='
                       && value == otherValue )
                     || ( operator == '<'
                          && value < otherValue )
                     || ( operator == '<='
                          && value <= otherValue )
                     || ( operator == '>='
                          && value >= otherValue )
                     || ( operator == '>'
                          && value > otherValue )
                     || ( operator == '<>'
                          && value != otherValue ) )
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
    }

    print( 'Bad value specifier : ' + valueSpecifier );

    return false;
}