github.com/Axway/agent-sdk@v1.1.101/pkg/filter/expr_contains.go (about)

     1  package filter
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  // ContainsExpr - Contains implementation. Check if the argument string is contained in value of specified filter data
     8  type ContainsExpr struct {
     9  	FilterType string
    10  	Name       string
    11  	Arg        string
    12  }
    13  
    14  func newContainsExpr(filterType, name, containsArg string) CallExpr {
    15  	return &ContainsExpr{
    16  		FilterType: filterType,
    17  		Name:       name,
    18  		Arg:        containsArg,
    19  	}
    20  }
    21  
    22  // GetType - Returns the CallType
    23  func (e *ContainsExpr) GetType() CallType {
    24  	return CONTAINS
    25  }
    26  
    27  // Execute - Returns true if the argument string is contained in value of specified filter data
    28  func (e *ContainsExpr) Execute(data Data) (interface{}, error) {
    29  	valueToCompare, ok := data.GetValue(e.FilterType, e.Name)
    30  	if ok && strings.Contains(valueToCompare, e.Arg) {
    31  		return true, nil
    32  	}
    33  
    34  	return false, nil
    35  }
    36  
    37  func (e *ContainsExpr) String() string {
    38  	return e.FilterType + "." + e.Name + ".Contains(\"" + e.Arg + "\")"
    39  }