Tests if the filter value, which contains a joker, is nearly equal to the
    tested value.

    If the tested value is a string or an array of string, it compares their
    lower case forms
495005
def _comparator_approximate_star(filter_value, tested_value):
    
    lower_filter_value = filter_value.lower()

    if is_string(tested_value):
        # Lower case comparison
        return _comparator_star(lower_filter_value, tested_value.lower())

    elif hasattr(tested_value, "__iter__"):
        # Extract a list of strings
        new_tested = [
            value.lower() for value in tested_value if is_string(value)
        ]

        if _comparator_star(lower_filter_value, new_tested):
            # Value found in the strings
            return True

    # Compare the raw values
    return _comparator_star(filter_value, tested_value) or _comparator_star(
        lower_filter_value, tested_value
    )
902646
def match_filter(filter, item)
      filter.each_pair do |key, value|
        unless item.key?(key)
          return false
        end
        unless value.is_a?(Array)
          return false if value != item[key]
        else
          return true if value.empty?
          return false unless value.include?(item[key])
        end
      end
      true
    end
875442
private boolean checkFilter(SCIMFilter filter) {
        switch (filter.getFilterType()) {
            case AND:
            case OR:
                return checkFilter(filter.getFilterComponents().get(0)) | checkFilter(filter.getFilterComponents().get(1));
            case EQUALITY:
                String name = filter.getFilterAttribute().getAttributeName();
                if ("id".equalsIgnoreCase(name) ||
                    "userName".equalsIgnoreCase(name)) {
                    return true;
                } else if (OriginKeys.ORIGIN.equalsIgnoreCase(name)) {
                    return false;
                } else {
                    throw new ScimException("Invalid filter attribute.", HttpStatus.BAD_REQUEST);
                }
            case PRESENCE:
            case STARTS_WITH:
            case CONTAINS:
                throw new ScimException("Wildcards are not allowed in filter.", HttpStatus.BAD_REQUEST);
            case GREATER_THAN:
            case GREATER_OR_EQUAL:
            case LESS_THAN:
            case LESS_OR_EQUAL:
                throw new ScimException("Invalid operator.", HttpStatus.BAD_REQUEST);
        }
        return false;
    }
147523
private boolean match(char []a, int aOff, int aLength, char []b)
  {
    int bLength = b.length;

    if (aLength != bLength)
      return false;

    for (int i = aLength - 1; i >= 0; i--) {
      char chA = a[aOff + i];
      char chB = b[i];

      if (chA != chB && chA + 'a' - 'A' != chB) {
        return false;
      }
    }

    return true;
  }
1228428
private boolean hasFilter(Filter filter, WhileMatchFilter whileMatchFilter) {
    if (filter == whileMatchFilter) {
      return true;
    }

    if (filter instanceof FilterList) {
      FilterList list = (FilterList) filter;
      for (Filter subFilter : list.getFilters()) {
        if (hasFilter(subFilter, whileMatchFilter)) {
          return true;
        }
      }
    }

    return false;
  }
572670
function contains(val) {
        var type = toString.call(val);
        if (map[type] === undefined)
            return false;

        var key = hash('' + val);
        if (map[type][key] === undefined)
            return false;

        var arr = map[type][key];
        for (var i = 0; i < arr.length; ++i) {
            if (arr[i] === val) return true;
        }

        return false;
    }
1258072
function matches(str, match) {
    if (Array.isArray(match)) {
        var l = match.length;
        for( var s=0; s < l; s++) {
            if ( mm(str,match[s])) {
                return true;
            }
        }
        return false;
    }
    return match.test(str);
}
297945
def _match_filters(parameter, filters=None):
        """"""
        for filter_obj in (filters or []):
            key = filter_obj['Key']
            option = filter_obj.get('Option', 'Equals')
            values = filter_obj.get('Values', [])

            what = None
            if key == 'Type':
                what = parameter.type
            elif key == 'KeyId':
                what = parameter.keyid

            if option == 'Equals'\
                    and not any(what == value for value in values):
                return False
            elif option == 'BeginsWith'\
                    and not any(what.startswith(value) for value in values):
                return False
        # True if no false match (or no filters at all)
        return True
640996
function(hash) {
	return function(row) {
		var testValue = function(value, rowValue) {
			if (value === '*' || value === '' || !value) {
				return true;
			}
			if (_.isString(rowValue)) {
				return (rowValue.toLowerCase() === value.toLowerCase());
			}
			if (_.isArray(rowValue)) {
				return (_.contains(_.map(rowValue, function(tag) {
					return _.isString(tag) && tag.toLowerCase();
				}), value.toLowerCase()) && true);
			}
			return false;				
		};
		
		// _.all makes sure all members of the hash pass
		return _.all(hash, function(value, key) {
			var rowValue = row.getAlias(key);
			
			if (rowValue) {
				
				// if the filter value is an array, then the rowValue must also be an array
				if (_.isArray(value) && _.isArray(rowValue)) {
					
					// expression is true if rowValue intersects completely with requested value.
					return _.intersection(value, rowValue).length === value.length;
				}

				// if the value is an array, but not the rowValue, only test the first index;
				return testValue(_.isArray(value) ? value[0] : value, rowValue)
			}
			return false;
		});
	};
}
294380
function findValue (arr, value) {
	value = purifyValue(value);

	for (var i = arr.length - 1; i >= 0; i--) {
		if (arr[i].val === value) {
			return arr[i].pos;
		};

		if (i === 0) {
			return -1;
		};
	};
}
514179
function(val, item) {
    if (_.isString(val)) return val.indexOf(item) !== -1;
    if (_.isArray(val))  return _.indexOf(val, item) !== -1;
    if (_.isObject(val)) return _.has(val, item);
    return false;
  }
1001085
function matchQueryPart(obj, queryKey, queryValue, treatObjAsValue) {
  var objValue = getDotValue(obj, queryKey),
    i,
    keys,
    firstChars,
    dollarFirstChars;

  // Check if the value is an array if we don't force a treatment as value
  if (util.isArray(objValue) && !treatObjAsValue) {
    // If the queryValue is an array, try to perform an exact match
    if (util.isArray(queryValue)) {
      return matchQueryPart(obj, queryKey, queryValue, true);
    }

    // Check if we are using an array-specific comparison function
    if (queryValue !== null && typeof queryValue === 'object' && !util.isRegExp(queryValue)) {
      keys = Object.keys(queryValue);
      for (i = 0; i < keys.length; i += 1) {
        if (arrayComparisonFunctions[keys[i]]) {
          return matchQueryPart(obj, queryKey, queryValue, true);
        }
      }
    }

    // If not, treat it as an array of { obj, query } where there needs to be at least one match
    for (i = 0; i < objValue.length; i += 1) {
      if (matchQueryPart({ k: objValue[i] }, 'k', queryValue)) {
        return true;
      } // k here could be any string
    }
    return false;
  }

  // queryValue is an actual object. Determine whether it contains comparison operators
  // or only normal fields. Mixed objects are not allowed
  if (
    queryValue !== null &&
    typeof queryValue === 'object' &&
    !util.isRegExp(queryValue) &&
    !util.isArray(queryValue)
  ) {
    keys = Object.keys(queryValue);
    firstChars = _.map(keys, function(item) {
      return item[0];
    });
    dollarFirstChars = _.filter(firstChars, function(c) {
      return c === '$';
    });

    if (dollarFirstChars.length !== 0 && dollarFirstChars.length !== firstChars.length) {
      throw new Error('You cannot mix operators and normal fields');
    }

    // queryValue is an object of this form: { $comparisonOperator1: value1, ... }
    if (dollarFirstChars.length > 0) {
      for (i = 0; i < keys.length; i += 1) {
        if (!comparisonFunctions[keys[i]]) {
          throw new Error('Unknown comparison function ' + keys[i]);
        }

        if (!comparisonFunctions[keys[i]](objValue, queryValue[keys[i]])) {
          return false;
        }
      }
      return true;
    }
  }

  // Using regular expressions with basic querying
  if (util.isRegExp(queryValue)) {
    return comparisonFunctions.$regex(objValue, queryValue);
  }

  // queryValue is either a native value or a normal object
  // Basic matching is possible
  if (!areThingsEqual(objValue, queryValue)) {
    return false;
  }

  return true;
}
1139363
function contains(value, elem) {
        if (validateHelpers.isArray(elem)) {
            for (var i = 0, len = elem.length; i < len; i += 1) {
                if (elem[i] === value) {
                    return true;
                }
            }
        }

        if (validateHelpers.isString(elem)) {
            return elem.indexOf(value) >= 0;
        }

        return false;
    }
346934
function compareValue(aVal, bVal) {
  var cmp, i, collate;
  if (isString(aVal) && isString(bVal)) {
    collate = _arrayOptions('sortCollate');
    return collate(aVal, bVal);
  } else if (isArray(aVal) && isArray(bVal)) {
    if (aVal.length < bVal.length) {
      return -1;
    } else if (aVal.length > bVal.length) {
      return 1;
    } else {
      for(i = 0; i < aVal.length; i++) {
        cmp = compareValue(aVal[i], bVal[i]);
        if (cmp !== 0) {
          return cmp;
        }
      }
      return 0;
    }
  }
  return aVal < bVal ? -1 : aVal > bVal ? 1 : 0;
}
1208371
function contains(arr, x) {
        for (var i = 0; i < arr.length; i++) {
            if (arr[i] === x) return true;
        }
        return false;
    }
524865
function checkFilter(filter, type, test, real) {
    if (type == Table.TYPE_DATETIME) {
        if (typeof real != 'object')
            real = new Date(real * 1000);
        if (filter == Table.FILTER_BETWEEN
                && Array.isArray(test) && test.length == 2) {
            test = [
                test[0] ? moment.unix(test[0]) : null,
                test[1] ? moment.unix(test[1]) : null,
            ];
        } else if (filter != Table.FILTER_BETWEEN) {
            test = moment.unix(test);
        } else {
            return null;
        }
    } else {
        if (filter == Table.FILTER_BETWEEN) {
            if (!Array.isArray(test) || test.length != 2)
                return null;
        }
    }

    switch (filter) {
        case Table.FILTER_LIKE:
            return real !== null && real.indexOf(test) != -1;
        case Table.FILTER_EQUAL:
            return real !== null && test == real;
        case Table.FILTER_BETWEEN:
            if (real === null)
                return false;
            if (test[0] !== null && real < test[0])
                return false;
            if (test[1] !== null && real > test[1])
                return false;
            return true;
        case Table.FILTER_NULL:
            return real === null;
        default:
            throw new Error("Unknown filter: " + filter);
    }

    return false;
}
1181774
function isEscapeingAt(string, index) {
	if (index === 0) { return false; }
	let i = index - 1;
	while (
		i >= 0 && string[i] === '\\'
	) { --i; }
	return (index - i) % 2 === 0;
}