Exemple #1
0
        public MyMatch Match()
        {
            if (Pattern == "*")
            {
                return(new MyMatch(true, 0, Src.Length - 1));
            }
            //divide pattern with * to multiple patterns without *
            //e.g. ab*cde*f ==> ab, cde, f
            string[] patterns     = Pattern.Split(new char[] { '*' });
            int      start        = 0;
            MyMatch  globalMatch  = new MyMatch(false, -1, -1);
            MyMatch  partialMatch = new MyMatch(false, -1, -1);

            for (int i = 0; i < patterns.Length; i++)
            {
                partialMatch = SimpleMatch(patterns[i], start);
                if (!partialMatch.matched)
                {
                    return(globalMatch);
                }
                if (i == 0)
                {
                    globalMatch.start = partialMatch.start;
                }
                start = partialMatch.end + 1;
            }

            globalMatch.end     = start - 1;
            globalMatch.matched = true;
            return(globalMatch);  // substring match
        }
Exemple #2
0
        public bool FullMatch()
        {
            MyMatch mMatch = Match();

            //return mMatch.matched && (mMatch.start == 0 || Pattern.StartsWith("*")) && (mMatch.end == Src.Length - 1 || Pattern.EndsWith("*"));
            return(mMatch.matched);
        }