Example #1
0
        private static bool MatchDelimiter(Delimiter[] delimiters, Itr itr)
        {
            foreach (Delimiter del in delimiters)
            {
                if (itr != del.toMatch)
                {
                    continue;
                }

                if (del.RegexPostMatch != null)
                {
                    if (itr.IsFinalIndex())
                    {
                        return(false);
                    }
                    if (!Regex.IsMatch(itr.Peek(1).ToString(), del.RegexPostMatch))
                    {
                        continue;
                    }
                }
                else if (del.PostMatch != null)
                {
                    var match = false;
                    foreach (string str in del.PostMatch)
                    {
                        if (itr.PeekAndEquals(del.toMatch.Length, str))
                        {
                            match = true;
                            break;
                        }
                    }
                    if (!match)
                    {
                        continue;
                    }
                }

                if (del.RegexPreMatch != null)
                {
                    if (itr.IsFirstIndex())
                    {
                        return(false);
                    }
                    if (!Regex.IsMatch(itr.Peek(-1).ToString(), del.RegexPreMatch))
                    {
                        continue;
                    }
                }
                else if (del.PreMatch != null)
                {
                    var match = false;
                    foreach (string str in del.PreMatch)
                    {
                        if (itr.PeekAndEquals(-str.Length, str))
                        {
                            match = true;
                            break;
                        }
                    }
                    if (!match)
                    {
                        continue;
                    }
                }

                return(true);
            }
            return(false);
        }