Ejemplo n.º 1
0
 internal Arg(string text)
 {
     this.text      = text;
     this.type      = ArgType.text;
     this.scope     = Regex.Scope.invalid;
     this.stringInt = null;
 }
Ejemplo n.º 2
0
 public Arg(Regex.Scope scope, int resultNumber)
 {
     this.type         = ArgType.regex;
     this.text         = null;
     this.scope        = scope;
     this.resultNumber = resultNumber;
     this.stringInt    = null;
 }
Ejemplo n.º 3
0
                internal void Append(Match match, Regex.Scope scope)
                {
                    if (!results.ContainsKey(scope))
                    {
                        results.Add(scope, new List <Match>(1));
                    }

                    results[scope].Add(match);
                }
Ejemplo n.º 4
0
                internal Match Get(Regex.Scope scope, int resultNumber)
                {
                    var matches = results[scope];

                    if (matches.Count <= resultNumber)
                    {
                        return(null);
                    }
                    return(matches[resultNumber]);
                }
Ejemplo n.º 5
0
                    internal static Arg Create(string text)
                    {
                        Rule.Regex.Scope scope = Regex.Scope.invalid;
                        // eh, simple if'ology would be sufficient
                        if (text.StartsWith("$s"))
                        {
                            scope = Regex.Scope.subject;
                        }
                        else if (text.StartsWith("$b"))
                        {
                            scope = Regex.Scope.body;
                        }
                        else if (text.StartsWith("$t"))
                        {
                            scope = Regex.Scope.to;
                        }
                        else if (text.StartsWith("$f"))
                        {
                            scope = Regex.Scope.from;
                        }
                        else if (text.StartsWith("$c"))
                        {
                            scope = Regex.Scope.cc;
                        }
                        else
                        {
                            return(new Arg(text));
                        }

                        var separator = text.IndexOf('.');

                        int       resultNumber;
                        StringInt stringInt = null;

                        if (separator < 0)
                        {
                            // $cN - Nth match, implicit 0th group
                            if (!int.TryParse(text.Substring(2, text.Length - 2), out resultNumber))
                            {
                                return(null);
                            }
                            return(new Arg(scope, resultNumber));
                        }
                        else if (separator <= 2)
                        {
                            // $c. .. just nope
                            return(null);
                        }
                        else
                        {
                            if (!int.TryParse(text.Substring(2, separator - 2), out resultNumber))
                            {
                                return(null);
                            }

                            int    group;
                            string group_sub = text.Substring(separator + 1, text.Length - separator - 1);
                            if (!int.TryParse(group_sub, out group))
                            {
                                // $cN.groupname
                                stringInt = new StringInt(group_sub);
                            }
                            else
                            {
                                // $cN.M - Nth match Mth group
                                stringInt = new StringInt(group);
                            }

                            return(new Arg(scope, resultNumber, stringInt));
                        }
                    }