Exemplo n.º 1
0
 public void Visit(PatternList value)
 {
     if (value.Patterns.Count > 1)
     {
         throw new NotSupportedException();
     }
     if (value.Patterns.Count > 0)
     {
         value.Patterns[0].Visit(this);
     }
 }
Exemplo n.º 2
0
        public PatternList Clone()
        {
            var result = new PatternList()
            {
                Options = Options
            };

            foreach (var pattern in Patterns)
            {
                result.Patterns.Add(pattern.Clone());
            }
            return(result);
        }
Exemplo n.º 3
0
 public virtual void Visit(PatternList op)
 {
     Visit(new StringLiteral(PatternParser.SqlServer.Render(op)));
 }
Exemplo n.º 4
0
 public virtual void Visit(PatternList op)
 {
 }
Exemplo n.º 5
0
        public virtual PatternList Parse(string str)
        {
            _pat      = new Pattern();
            _strMatch = new StringMatch();
            Anchor endAnchor = null;

            if (string.IsNullOrEmpty(str))
            {
                return(new PatternList());
            }

            if (str[0] == this.Pattern_Anything)
            {
                str = str.TrimStart(this.Pattern_Anything);
            }
            else
            {
                _pat.Matches.Add(new Anchor()
                {
                    Type = AnchorType.Start_Absolute
                });
            }
            if (!string.IsNullOrEmpty(str) && str[str.Length - 1] == this.Pattern_Anything)
            {
                str = str.TrimEnd(this.Pattern_Anything);
            }
            else
            {
                endAnchor = new Anchor()
                {
                    Type = AnchorType.End_Absolute
                };
            }

            var  i       = 0;
            bool inRange = false;

            while (i < str.Length)
            {
                if (inRange)
                {
                    if (str[i] == ']')
                    {
                        inRange = false;
                        _pat.Matches.Add(_set);
                        _set = null;
                    }
                    else if (_set.Chars.Count > 0 && str[i] == this.Pattern_SetRange && (i + 1) < str.Length && str[i + 1] != ']')
                    {
                        _set.AddRange((char)(_set.Chars.Last() + 1), str[i + 1]);
                        i++;
                    }
                    else
                    {
                        _set.Chars.Add(str[i]);
                    }
                }
                else if (str[i] == this.Pattern_Anything)
                {
                    FinishStringMatch();
                    _set = new CharSet('.');
                    _set.Repeat.MinCount = 0;
                    _set.Repeat.MaxCount = int.MaxValue;
                    _pat.Matches.Add(_set);
                    _set = null;
                }
                else if (str[i] == this.Pattern_SingleChar)
                {
                    FinishStringMatch();
                    _set = new CharSet('.');
                    _set.Repeat.MinCount = 1;
                    _set.Repeat.MaxCount = 1;
                    _pat.Matches.Add(_set);
                    _set = null;
                }
                else if (str[i] == this.Pattern_SingleDigit)
                {
                    FinishStringMatch();
                    _set = new CharSet('d');
                    _set.Repeat.MinCount = 1;
                    _set.Repeat.MaxCount = 1;
                    _pat.Matches.Add(_set);
                    _set = null;
                }
                else if (str[i] == '[' && !inRange && AllowCharSet)
                {
                    FinishStringMatch();
                    inRange = true;
                    _set    = new CharSet();
                    if ((i + 1) < str.Length && str[i + 1] == this.Pattern_InverseSet)
                    {
                        _set.InverseSet = true;
                        i++;
                    }
                }
                else if (str[i] == this.Pattern_Escape)
                {
                    i++;
                    _strMatch.Match.Append(str[i]);
                }
                else
                {
                    _strMatch.Match.Append(str[i]);
                }
                i++;
            }

            if (_strMatch.Match.Length > 0)
            {
                _pat.Matches.Add(_strMatch);
            }
            if (endAnchor != null)
            {
                _pat.Matches.Add(endAnchor);
            }

            var patOpts = new PatternList();

            patOpts.Patterns.Add(_pat);
            patOpts.Visit(RegexParser.Simplify);
            return(patOpts);
        }
 public void Visit(PatternList op)
 {
     _writer.WriteString(PatternParser.SqlServer.Render(op));
 }
Exemplo n.º 7
0
 public virtual IExpression Clone(PatternList op)
 {
     return(op.Clone());
 }
Exemplo n.º 8
0
 void IExpressionVisitor.Visit(PatternList op)
 {
     _clone = Clone(op);
 }
Exemplo n.º 9
0
        internal static IExpression FromMethod(string name, IExpression left, IExpression right)
        {
            if (right is StringLiteral str)
            {
                switch (name.ToLowerInvariant())
                {
                case "startswith":
                    right = new PatternList()
                    {
                        Patterns =
                        {
                            new Pattern()
                            {
                                Matches =
                                {
                                    new Anchor()
                                    {
                                        Type = AnchorType.Start_Absolute
                                    },
                                    new StringMatch(str.Value)
                                }
                            }
                        }
                    };
                    break;

                case "endswith":
                    right = new PatternList()
                    {
                        Patterns =
                        {
                            new Pattern()
                            {
                                Matches =
                                {
                                    new StringMatch(str.Value),
                                    new Anchor()
                                    {
                                        Type = AnchorType.End_Absolute
                                    }
                                }
                            }
                        }
                    };
                    break;

                case "contains":
                    right = new PatternList()
                    {
                        Patterns =
                        {
                            new Pattern()
                            {
                                Matches ={ new StringMatch(str.Value)               }
                            }
                        }
                    };
                    break;

                default:
                    throw new NotSupportedException();
                }

                return(new LikeOperator()
                {
                    Left = left, Right = right
                }.Normalize());
            }
            else
            {
                switch (name.ToLowerInvariant())
                {
                case "startswith":
                    return(new Functions.StartsWith()
                    {
                        String = left,
                        Find = right
                    });

                case "endswith":
                    return(new Functions.EndsWith()
                    {
                        String = left,
                        Find = right
                    });

                case "contains":
                    return(new Functions.Contains()
                    {
                        String = left,
                        Find = right
                    });

                default:
                    throw new NotSupportedException();
                }
            }
        }