SingletonChar() статический приватный Метод

static private SingletonChar ( String set ) : char
set String
Результат char
Пример #1
0
 internal RegexNode ReduceSet()
 {
     if (RegexCharClass.IsEmpty(this._str))
     {
         this._type = 0x16;
         this._str  = null;
     }
     else if (RegexCharClass.IsSingleton(this._str))
     {
         this._ch    = RegexCharClass.SingletonChar(this._str);
         this._str   = null;
         this._type += -2;
     }
     else if (RegexCharClass.IsSingletonInverse(this._str))
     {
         this._ch    = RegexCharClass.SingletonChar(this._str);
         this._str   = null;
         this._type += -1;
     }
     return(this);
 }
Пример #2
0
        /*
         * ReduceSet:
         *
         * Simple optimization. If a set is a singleton, an inverse singleton,
         * or empty, it's transformed accordingly.
         */

        internal RegexNode ReduceSet()
        {
            // Extract empty-set, one and not-one case as special

            if (RegexCharClass.IsEmpty(_str))
            {
                _type = Nothing;
                _str  = null;
            }
            else if (RegexCharClass.IsSingleton(_str))
            {
                _ch    = RegexCharClass.SingletonChar(_str);
                _str   = null;
                _type += (One - Set);
            }
            else if (RegexCharClass.IsSingletonInverse(_str))
            {
                _ch    = RegexCharClass.SingletonChar(_str);
                _str   = null;
                _type += (Notone - Set);
            }

            return(this);
        }
Пример #3
0
        /// <summary>
        /// Simple optimization. If a set is a singleton, an inverse singleton,
        /// or empty, it's transformed accordingly.
        /// </summary>
        private RegexNode ReduceSet()
        {
            // Extract empty-set, one and not-one case as special

            if (RegexCharClass.IsEmpty(Str))
            {
                NType = Nothing;
                Str   = null;
            }
            else if (RegexCharClass.IsSingleton(Str))
            {
                Ch     = RegexCharClass.SingletonChar(Str);
                Str    = null;
                NType += (One - Set);
            }
            else if (RegexCharClass.IsSingletonInverse(Str))
            {
                Ch     = RegexCharClass.SingletonChar(Str);
                Str    = null;
                NType += (Notone - Set);
            }

            return(this);
        }
Пример #4
0
        protected override bool FindFirstChar()
        {
            if (0 != (_code.Anchors & (RegexFCD.Beginning | RegexFCD.Start | RegexFCD.EndZ | RegexFCD.End)))
            {
                if (!_code.RightToLeft)
                {
                    if ((0 != (_code.Anchors & RegexFCD.Beginning) && runtextpos > runtextbeg) ||
                        (0 != (_code.Anchors & RegexFCD.Start) && runtextpos > runtextstart))
                    {
                        runtextpos = runtextend;
                        return(false);
                    }
                    if (0 != (_code.Anchors & RegexFCD.EndZ) && runtextpos < runtextend - 1)
                    {
                        runtextpos = runtextend - 1;
                    }
                    else if (0 != (_code.Anchors & RegexFCD.End) && runtextpos < runtextend)
                    {
                        runtextpos = runtextend;
                    }
                }
                else
                {
                    if ((0 != (_code.Anchors & RegexFCD.End) && runtextpos < runtextend) ||
                        (0 != (_code.Anchors & RegexFCD.EndZ) && (runtextpos < runtextend - 1 ||
                                                                  (runtextpos == runtextend - 1 && CharAt(runtextpos) != '\n'))) ||
                        (0 != (_code.Anchors & RegexFCD.Start) && runtextpos < runtextstart))
                    {
                        runtextpos = runtextbeg;
                        return(false);
                    }
                    if (0 != (_code.Anchors & RegexFCD.Beginning) && runtextpos > runtextbeg)
                    {
                        runtextpos = runtextbeg;
                    }
                }

                if (_code.BMPrefix != null)
                {
                    return(_code.BMPrefix.IsMatch(runtext, runtextpos, runtextbeg, runtextend));
                }

                return(true); // found a valid start or end anchor
            }
            else if (_code.BMPrefix != null)
            {
                runtextpos = _code.BMPrefix.Scan(runtext, runtextpos, runtextbeg, runtextend);

                if (runtextpos == -1)
                {
                    runtextpos = (_code.RightToLeft ? runtextbeg : runtextend);
                    return(false);
                }

                return(true);
            }
            else if (_code.FCPrefix == null)
            {
                return(true);
            }

            _rightToLeft     = _code.RightToLeft;
            _caseInsensitive = _code.FCPrefix.GetValueOrDefault().CaseInsensitive;
            string set = _code.FCPrefix.GetValueOrDefault().Prefix;

            if (RegexCharClass.IsSingleton(set))
            {
                char ch = RegexCharClass.SingletonChar(set);

                for (int i = Forwardchars(); i > 0; i--)
                {
                    if (ch == Forwardcharnext())
                    {
                        Backwardnext();
                        return(true);
                    }
                }
            }
            else
            {
                for (int i = Forwardchars(); i > 0; i--)
                {
                    if (RegexCharClass.CharInClass(Forwardcharnext(), set))
                    {
                        Backwardnext();
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #5
0
        protected override bool FindFirstChar()
        {
            int    i;
            String set;

            if (0 != (_code._anchors & (RegexFCD.Beginning | RegexFCD.Start | RegexFCD.EndZ | RegexFCD.End)))
            {
                if (!_code._rightToLeft)
                {
                    if ((0 != (_code._anchors & RegexFCD.Beginning) && _runtextpos > _runtextbeg) ||
                        (0 != (_code._anchors & RegexFCD.Start) && _runtextpos > _runtextstart))
                    {
                        _runtextpos = _runtextend;
                        return(false);
                    }
                    if (0 != (_code._anchors & RegexFCD.EndZ) && _runtextpos < _runtextend - 1)
                    {
                        _runtextpos = _runtextend - 1;
                    }
                    else if (0 != (_code._anchors & RegexFCD.End) && _runtextpos < _runtextend)
                    {
                        _runtextpos = _runtextend;
                    }
                }
                else
                {
                    if ((0 != (_code._anchors & RegexFCD.End) && _runtextpos < _runtextend) ||
                        (0 != (_code._anchors & RegexFCD.EndZ) && (_runtextpos < _runtextend - 1 ||
                                                                   (_runtextpos == _runtextend - 1 && CharAt(_runtextpos) != '\n'))) ||
                        (0 != (_code._anchors & RegexFCD.Start) && _runtextpos < _runtextstart))
                    {
                        _runtextpos = _runtextbeg;
                        return(false);
                    }
                    if (0 != (_code._anchors & RegexFCD.Beginning) && _runtextpos > _runtextbeg)
                    {
                        _runtextpos = _runtextbeg;
                    }
                }

                if (_code._bmPrefix != null)
                {
                    return(_code._bmPrefix.IsMatch(_runtext, _runtextpos, _runtextbeg, _runtextend));
                }

                return(true); // found a valid start or end anchor
            }
            else if (_code._bmPrefix != null)
            {
                _runtextpos = _code._bmPrefix.Scan(_runtext, _runtextpos, _runtextbeg, _runtextend);

                if (_runtextpos == -1)
                {
                    _runtextpos = (_code._rightToLeft ? _runtextbeg : _runtextend);
                    return(false);
                }

                return(true);
            }
            else if (_code._fcPrefix == null)
            {
                return(true);
            }

            _rightToLeft     = _code._rightToLeft;
            _caseInsensitive = _code._fcPrefix.CaseInsensitive;
            set = _code._fcPrefix.Prefix;

            if (RegexCharClass.IsSingleton(set))
            {
                char ch = RegexCharClass.SingletonChar(set);

                for (i = Forwardchars(); i > 0; i--)
                {
                    if (ch == Forwardcharnext())
                    {
                        Backwardnext();
                        return(true);
                    }
                }
            }
            else
            {
                for (i = Forwardchars(); i > 0; i--)
                {
                    if (RegexCharClass.CharInClass(Forwardcharnext(), set))
                    {
                        Backwardnext();
                        return(true);
                    }
                }
            }
            return(false);
        }
Пример #6
0
        protected override bool FindFirstChar()
        {
            int    i;
            String set;

            if (0 != (runanchors & (RegexFCD.Beginning | RegexFCD.Start | RegexFCD.EndZ | RegexFCD.End)))
            {
                if (!runcode._rightToLeft)
                {
                    if ((0 != (runanchors & RegexFCD.Beginning) && runtextpos > runtextbeg) ||
                        (0 != (runanchors & RegexFCD.Start) && runtextpos > runtextstart))
                    {
                        runtextpos = runtextend;
                        return(false);
                    }
                    if (0 != (runanchors & RegexFCD.EndZ) && runtextpos < runtextend - 1)
                    {
                        runtextpos = runtextend - 1;
                    }
                    else if (0 != (runanchors & RegexFCD.End) && runtextpos < runtextend)
                    {
                        runtextpos = runtextend;
                    }
                }
                else
                {
                    if ((0 != (runanchors & RegexFCD.End) && runtextpos < runtextend) ||
                        (0 != (runanchors & RegexFCD.EndZ) && (runtextpos < runtextend - 1 ||
                                                               (runtextpos == runtextend - 1 && CharAt(runtextpos) != '\n'))) ||
                        (0 != (runanchors & RegexFCD.Start) && runtextpos < runtextstart))
                    {
                        runtextpos = runtextbeg;
                        return(false);
                    }
                    if (0 != (runanchors & RegexFCD.Beginning) && runtextpos > runtextbeg)
                    {
                        runtextpos = runtextbeg;
                    }
                }

                if (runbmPrefix != null)
                {
                    return(runbmPrefix.IsMatch(runtext, runtextpos, runtextbeg, runtextend));
                }
            }
            else if (runbmPrefix != null)
            {
                runtextpos = runbmPrefix.Scan(runtext, runtextpos, runtextbeg, runtextend);

                if (runtextpos == -1)
                {
                    runtextpos = (runcode._rightToLeft ? runtextbeg : runtextend);
                    return(false);
                }

                return(true);
            }

            if (runfcPrefix == null)
            {
                return(true);
            }

            runrtl = runcode._rightToLeft;
            runci  = runfcPrefix.CaseInsensitive;
            set    = runfcPrefix.Prefix;

            if (RegexCharClass.IsSingleton(set))
            {
                char ch = RegexCharClass.SingletonChar(set);

                for (i = Forwardchars(); i > 0; i--)
                {
                    if (ch == Forwardcharnext())
                    {
                        Backwardnext();
                        return(true);
                    }
                }
            }
            else
            {
                for (i = Forwardchars(); i > 0; i--)
                {
                    if (RegexCharClass.CharInSet(Forwardcharnext(), set, String.Empty))
                    {
                        Backwardnext();
                        return(true);
                    }
                }
            }
            return(false);
        }
        protected override bool FindFirstChar()
        {
            int num;

            if ((this.runanchors & 0x35) != 0)
            {
                if (!this.runcode._rightToLeft)
                {
                    if ((((this.runanchors & 1) != 0) && (base.runtextpos > base.runtextbeg)) || (((this.runanchors & 4) != 0) && (base.runtextpos > base.runtextstart)))
                    {
                        base.runtextpos = base.runtextend;
                        return(false);
                    }
                    if (((this.runanchors & 0x10) != 0) && (base.runtextpos < (base.runtextend - 1)))
                    {
                        base.runtextpos = base.runtextend - 1;
                    }
                    else if (((this.runanchors & 0x20) != 0) && (base.runtextpos < base.runtextend))
                    {
                        base.runtextpos = base.runtextend;
                    }
                }
                else
                {
                    if (((((this.runanchors & 0x20) != 0) && (base.runtextpos < base.runtextend)) || (((this.runanchors & 0x10) != 0) && ((base.runtextpos < (base.runtextend - 1)) || ((base.runtextpos == (base.runtextend - 1)) && (this.CharAt(base.runtextpos) != '\n'))))) || (((this.runanchors & 4) != 0) && (base.runtextpos < base.runtextstart)))
                    {
                        base.runtextpos = base.runtextbeg;
                        return(false);
                    }
                    if (((this.runanchors & 1) != 0) && (base.runtextpos > base.runtextbeg))
                    {
                        base.runtextpos = base.runtextbeg;
                    }
                }
                if (this.runbmPrefix != null)
                {
                    return(this.runbmPrefix.IsMatch(base.runtext, base.runtextpos, base.runtextbeg, base.runtextend));
                }
            }
            else if (this.runbmPrefix != null)
            {
                base.runtextpos = this.runbmPrefix.Scan(base.runtext, base.runtextpos, base.runtextbeg, base.runtextend);
                if (base.runtextpos == -1)
                {
                    base.runtextpos = this.runcode._rightToLeft ? base.runtextbeg : base.runtextend;
                    return(false);
                }
                return(true);
            }
            if (this.runfcPrefix == null)
            {
                return(true);
            }
            this.runrtl = this.runcode._rightToLeft;
            this.runci  = this.runfcPrefix.CaseInsensitive;
            string prefix = this.runfcPrefix.Prefix;

            if (RegexCharClass.IsSingleton(prefix))
            {
                char ch = RegexCharClass.SingletonChar(prefix);
                for (num = this.Forwardchars(); num > 0; num--)
                {
                    if (ch == this.Forwardcharnext())
                    {
                        this.Backwardnext();
                        return(true);
                    }
                }
            }
            else
            {
                for (num = this.Forwardchars(); num > 0; num--)
                {
                    if (RegexCharClass.CharInSet(this.Forwardcharnext(), prefix, string.Empty))
                    {
                        this.Backwardnext();
                        return(true);
                    }
                }
            }
            return(false);
        }