Esempio n. 1
0
 public StringTestEntry(string str, StringMatchMode mode, bool caseInvariant)
 {
     _str         = caseInvariant ? str.ToLowerInvariant() : str;
     _mode        = mode;
     _strAsDouble = AsDouble(_str);
     _strAsBool   = AsBool(_str);
 }
Esempio n. 2
0
 public StringTestEntry(string str, StringMatchMode mode)
 {
     _str         = str.ToLowerInvariant();
     _mode        = mode;
     _strAsDouble = AsDouble(_str);
     _strAsBool   = AsBool(_str);
 }
Esempio n. 3
0
 public Criterion(string propertyName, CriteriaOperator @operator, object value,
     StringMatchMode matchMode, bool caseInsensitive)
     : this(propertyName, @operator, value)
 {
     if (@operator != CriteriaOperator.Like && @operator != CriteriaOperator.NotLike)
         throw new ArgumentException();
     this.matchMode = matchMode;
     this.caseInsensitive = caseInsensitive;
 }
Esempio n. 4
0
 public Criterion(string propertyName, CriteriaOperator @operator, object value,
                  StringMatchMode matchMode, bool caseInsensitive)
     : this(propertyName, @operator, value)
 {
     if (@operator != CriteriaOperator.Like && @operator != CriteriaOperator.NotLike)
     {
         throw new ArgumentException();
     }
     this.matchMode       = matchMode;
     this.caseInsensitive = caseInsensitive;
 }
Esempio n. 5
0
        private static string PrepareQuery(string query, StringMatchMode mode)
        {
            var result = new StringBuilder((int)(query.Length * 1.2 + 2));

            result.Append(mode != StringMatchMode.IncludedWithin ? @"^" : @"\b");

            for (var i = 0; i < query.Length; i++)
            {
                var c = query[i];

                if (c == '\\')
                {
                    var n = i + 1 < query.Length ? query[i + 1] : (char)0;
                    if (IsQuerySymbol(n))
                    {
                        i++;
                        AppendEscaped(n, result);
                        continue;
                    }
                }

                if (c == '*')
                {
                    result.Append(".*");
                }
                else if (c == '?')
                {
                    result.Append(".");
                }
                else
                {
                    AppendEscaped(query[i], result);
                }
            }

            if (mode == StringMatchMode.CompleteMatch)
            {
                result.Append(@"$");
            }

            return(result.ToString());
        }
Esempio n. 6
0
        private MatchMode convertMatchMode(StringMatchMode stringMatchMode)
        {
            switch (stringMatchMode)
            {
            case StringMatchMode.Exact:
                return(MatchMode.Exact);

            case StringMatchMode.Anywhere:
                return(MatchMode.Anywhere);

            case StringMatchMode.Start:
                return(MatchMode.Start);

            case StringMatchMode.End:
                return(MatchMode.End);

            default:
                throw new ArgumentException("Invalid argument.", "stringMatchMode");
            }
        }
Esempio n. 7
0
        private static ITestEntry CreateTestEntry(string value, RegexFactory regexFactory, StringMatchMode mode)
        {
            if (value.Length > 1)
            {
                if (value[0] == '"' && value[value.Length - 1] == '"')
                {
                    return(new StringTestEntry(value.Substring(1, value.Length - 2), mode));
                }

                if (value[0] == '\'' && value[value.Length - 1] == '\'')
                {
                    return(new StringTestEntry(value.Substring(1, value.Length - 2), StringMatchMode.CompleteMatch));
                }

                if (value[0] == '`' && value[value.Length - 1] == '`')
                {
                    try {
                        var regex = new Regex(value.Substring(1, value.Length - 2), RegexOptions.Compiled | RegexOptions.IgnoreCase);
                        return(new RegexTestEntry(regex));
                    } catch (Exception) {
                        return(new ConstTestEntry(false));
                    }
                }
            }

            if (RegexFromQuery.IsQuery(value))
            {
                return(new RegexTestEntry(regexFactory(value, mode)));
            }

            return(new StringTestEntry(value, mode));
        }
 public StringMatcher(string matcher, StringMatchMode matchMode = StringMatchMode.Contains)
 {
     this.matchMode = matchMode;
     this.matcher = matcher;
 }
Esempio n. 9
0
 public static Regex Create(string query, StringMatchMode mode, bool ignoreCase)
 {
     return(new Regex(PrepareQuery(query, mode), ignoreCase ? RegexOptions.Compiled | RegexOptions.IgnoreCase : RegexOptions.Compiled));
 }
Esempio n. 10
0
        private MatchMode convertMatchMode(StringMatchMode stringMatchMode)
        {
            switch (stringMatchMode)
            {
                case StringMatchMode.Exact:
                    return MatchMode.Exact;

                case StringMatchMode.Anywhere:
                    return MatchMode.Anywhere;

                case StringMatchMode.Start:
                    return MatchMode.Start;

                case StringMatchMode.End:
                    return MatchMode.End;

                default:
                    throw new ArgumentException("Invalid argument.", "stringMatchMode");
            }
        }
Esempio n. 11
0
 public StringMatcher(string matcher, StringMatchMode matchMode = StringMatchMode.Contains)
 {
     this.matchMode = matchMode;
     this.matcher   = matcher;
 }
Esempio n. 12
0
 public StringMatchArguments(StringMatchMode mode, string value, bool ignoreCase)
 {
     this.Mode       = mode;
     this.Value      = value;
     this.IgnoreCase = ignoreCase;
 }