Пример #1
0
        private static bool SplitOnDot(Itr itr)
        {
            if (itr == ".")
            {
                if (itr.IsFirstIndex() || itr.Peek(-1) == ' ')              //dot is first index or white space
                {
                    if (!itr.IsFinalIndex())                                //not final index
                    {
                        if (Regex.IsMatch(itr.Peek(1).ToString(), @"[\d]")) //digit
                        {
                            return(false);
                        }
                    }
                }

                if (itr.IsFirstIndex() || itr.Peek(-1) == '.')
                {
                    return(true);
                }

                if (Regex.IsMatch(itr.Peek(-1).ToString(), @"[\d]")) //if it's got a digit before
                {
                    int i = -2;
                    while (true)
                    {
                        if (Regex.IsMatch(itr.Peek(i).ToString(), @"[\D]"))     //not a digit
                        {
                            if (Regex.IsMatch(itr.Peek(i).ToString(), @"[\w]")) //is a word character
                            {
                                return(true);
                            }
                        }

                        if (itr.Index + --i < 0)
                        {
                            break;
                        }
                    }
                }
            }
            return(false);
        }
Пример #2
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);
        }