Beispiel #1
0
        public static RegexpState create(Env env, Regexp regexp, StringValue subject)
        {
            RegexpState state = create(env, regexp);

            state.setSubject(env, subject);

            return(state);
        }
Beispiel #2
0
        private void init(Regexp regexp)
        {
            _regexp = regexp;

            int nGroup = regexp._nGroup;

            if (_groupBegin.length < nGroup)
            {
                _groupBegin = new int[nGroup];
                _groupEnd   = new int[nGroup];

                _isGroupFinalized = new boolean[nGroup];
            }
            else
            {
                for (int i = 0; i < nGroup; i++)
                {
                    _groupBegin[i]       = 0;
                    _groupEnd[i]         = 0;
                    _isGroupFinalized[i] = false;
                }
            }

            int nLoop = regexp._nLoop;

            if (_loopCount.length < nLoop)
            {
                _loopCount  = new int[nLoop];
                _loopOffset = new int[nLoop];
            }
            else
            {
                for (int i = 0; i < nLoop; i++)
                {
                    _loopCount[i]  = 0;
                    _loopOffset[i] = 0;
                }
            }

            _subject       = null;
            _subjectLength = 0;
            _isGlobal      = false;

            _first = 0;
            _start = 0;

            _prefix    = null; // initial string
            _minLength = 0;    // minimum length possible for this regexp

            _isUnicode    = false;
            _isPHP5String = false;

            _isUTF8 = false;
            _isEval = false;
        }
Beispiel #3
0
        public static RegexpState create(Env env, Regexp regexp)
        {
            RegexpState state = env.allocateRegexpState();

            if (state == null)
            {
                state = new RegexpState();
            }

            state.init(regexp);

            return(state);
        }
        public Regexp get(StringValue str)
        {
            int head = _head;

            for (int i = 0; i < MAX_SIZE; i++)
            {
                Regexp regexp = _cache[(head + i) % MAX_SIZE];

                if (regexp == null)
                {
                    break;
                }
                else
                {
                    StringValue rawRegexp = regexp.getRawRegexp();

                    if (rawRegexp == str || rawRegexp.equals(str))
                    {
                        return(regexp);
                    }
                }
            }

            Regexp regexp = RegexpModule.createRegexp(str);

            head = head - 1;

            if (head < 0)
            {
                head = MAX_SIZE - 1;
            }

            _cache[head] = regexp;
            _head        = head;

            return(regexp);
        }