public void It_should_match_any_string_by_regex() { const string input = "Julia Spólnik"; var result = OdbString.Matches("Julia.*", input); Assert.That(result, Is.True); }
public override bool Evaluate(object candidate) { string regExp; if (candidate == null) { return(false); } candidate = AsAttributeValuesMapValue(candidate); if (candidate == null) { return(false); } // Like operator only work with String if (!(candidate is string)) { throw new OdbRuntimeException( NDatabaseError.QueryAttributeTypeNotSupportedInLikeExpression.AddParameter( candidate.GetType().FullName)); } var value = (string)candidate; var criterionValue = (string)TheObject; if (criterionValue.IndexOf("%", StringComparison.Ordinal) != -1) { regExp = criterionValue.Replace("%", "(.)*"); return(_isCaseSensitive ? OdbString.Matches(regExp, value) : OdbString.Matches(regExp.ToLower(), value.ToLower())); } if (!_isCaseSensitive) { criterionValue = criterionValue.ToLower(); value = value.ToLower(); } regExp = string.Format(LikePattern, criterionValue); return(OdbString.Matches(regExp, value)); }
public override bool Match(object valueToMatch) { string regExp = null; if (valueToMatch == null) { return(false); } // If it is a AttributeValuesMap, then gets the real value from the map if (valueToMatch is AttributeValuesMap) { AttributeValuesMap attributeValues = (AttributeValuesMap)valueToMatch; valueToMatch = attributeValues[attributeName]; } if (valueToMatch == null) { return(false); } // Like operator only work with String if (!(valueToMatch is string)) { throw new ODBRuntimeException(NeoDatisError.QueryAttributeTypeNotSupportedInLikeExpression .AddParameter(valueToMatch.GetType().FullName)); } string value = (string)valueToMatch; if (criterionValue.IndexOf("%") != -1) { regExp = OdbString.ReplaceToken(criterionValue, "%", "(.)*"); if (isCaseSensitive) { bool b = value != null && OdbString.Matches(regExp, value); return(b); } return(value != null && OdbString.Matches(regExp.ToLower() , value.ToLower())); } if (isCaseSensitive) { regExp = string.Format("(.)*%s(.)*", criterionValue); return(value != null && OdbString.Matches(regExp, value)); } regExp = string.Format("(.)*%s(.)*", criterionValue.ToLower()); return(value != null && OdbString.Matches(regExp, value.ToLower())); }