/**
         * Match a character sequence against this pattern.
         * 
         * @param rcs
         *            the sequence to match. Must not be null but the Length of the
         *            sequence is permitted to be 0.
         * @return offset within <code>rcs</code> of the first occurrence of this
         *         pattern; -1 if this pattern does not appear at any position of
         *         <code>rcs</code>.
         */
        public int match(RawCharSequence rcs)
        {
            int needleLen = needle.Length;
            byte first = needle[0];

            byte[] text = rcs.buffer;
            int matchPos = rcs.startPtr;
            int maxPos = rcs.endPtr - needleLen;

            for (; matchPos < maxPos; matchPos++)
            {
                if (neq(first, text[matchPos]))
                {
                    while (++matchPos < maxPos && neq(first, text[matchPos]))
                    {
                        /* skip */
                    }
                    if (matchPos == maxPos)
                        return -1;
                }

                int si = ++matchPos;

                bool outer_continue = false;
                for (int j = 1; j < needleLen; j++, si++)
                {
                    if (neq(needle[j], text[si]))
                        outer_continue = true;
                }

                if (outer_continue)
                    continue;

                return matchPos - 1;
            }
            return -1;
        }
Example #2
0
        /**
         * Match a character sequence against this pattern.
         *
         * @param rcs
         *            the sequence to match. Must not be null but the Length of the
         *            sequence is permitted to be 0.
         * @return offset within <code>rcs</code> of the first occurrence of this
         *         pattern; -1 if this pattern does not appear at any position of
         *         <code>rcs</code>.
         */
        public int match(RawCharSequence rcs)
        {
            int needleLen = needle.Length;
            byte first = needle[0];

            byte[] text = rcs.buffer;
            int matchPos = rcs.startPtr;
            int maxPos = rcs.endPtr - needleLen;

            for (; matchPos < maxPos; matchPos++)
            {
            OUTER:
                if (neq(first, text[matchPos]))
                {
                    while (++matchPos < maxPos && neq(first, text[matchPos]))
                    {
                        /* skip */
                    }
                    if (matchPos == maxPos)
                        return -1;
                }

                int si = ++matchPos;
                for (int j = 1; j < needleLen; j++, si++)
                {
                    if (neq(needle[j], text[si]))
                        goto OUTER; // [henon] continue OUTER; in java
                }
                return matchPos - 1;
            }
            return -1;
        }