Ejemplo n.º 1
0
        internal static bool MatchString(LimitChecker limitChecker, CultureInfo cultureInfo, string content, string pattern, ContentFlags flags)
        {
            if (!limitChecker.CheckAndIncrementContentRestrictionCount(1, content))
            {
                return(false);
            }
            CompareOptions compareOptions = RestrictionEvaluator.GetCompareOptions(flags);
            ContentFlags   contentFlags   = flags & (ContentFlags.SubString | ContentFlags.Prefix);
            CompareInfo    compareInfo    = cultureInfo.CompareInfo;

            switch (contentFlags)
            {
            case ContentFlags.FullString:
                return(compareInfo.Compare(content, pattern, compareOptions) == 0);

            case ContentFlags.SubString:
                return(compareInfo.IndexOf(content, pattern, compareOptions) != -1);

            case ContentFlags.Prefix:
                return(compareInfo.IsPrefix(content, pattern, compareOptions));

            default:
                throw new InvalidRuleException(string.Format("Not supported content flags {0}", flags));
            }
        }
Ejemplo n.º 2
0
        private static bool MatchByteArray(LimitChecker limitChecker, byte[] content, byte[] pattern, ContentFlags flags)
        {
            if (!limitChecker.CheckAndIncrementContentRestrictionCount(1, content))
            {
                return(false);
            }
            switch (flags & (ContentFlags.SubString | ContentFlags.Prefix))
            {
            case ContentFlags.FullString:
                return(RuleUtil.EqualsByteArray(content, pattern));

            case ContentFlags.SubString:
                return(RuleUtil.Contains(content, pattern));

            case ContentFlags.Prefix:
                return(RuleUtil.IsPrefix(content, pattern));

            default:
                throw new InvalidRuleException(string.Format("Not supported content flags {0}", flags));
            }
        }