Beispiel #1
0
        /// <summary>Match a character sequence against this pattern.</summary>
        /// <remarks>Match a character sequence against this pattern.</remarks>
        /// <param name="rcs">
        /// the sequence to match. Must not be null but the length of the
        /// sequence is permitted to be 0.
        /// </param>
        /// <returns>
        /// 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>.
        /// </returns>
        public virtual 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]))
                    {
                    }
                    if (matchPos == maxPos)
                    {
                        return(-1);
                    }
                }
                int si = ++matchPos;
                for (int j = 1; j < needleLen; j++, si++)
                {
                    if (Neq(needle[j], text[si]))
                    {
                        goto OUTER_continue;
                    }
                }
                return(matchPos - 1);

                OUTER_continue :;
            }
            OUTER_break :;
            return(-1);
        }
		/// <summary>Match a character sequence against this pattern.</summary>
		/// <remarks>Match a character sequence against this pattern.</remarks>
		/// <param name="rcs">
		/// the sequence to match. Must not be null but the length of the
		/// sequence is permitted to be 0.
		/// </param>
		/// <returns>
		/// 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>.
		/// </returns>
		public virtual 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]))
					{
					}
					if (matchPos == maxPos)
					{
						return -1;
					}
				}
				int si = ++matchPos;
				for (int j = 1; j < needleLen; j++, si++)
				{
					if (Neq(needle[j], text[si]))
					{
						goto OUTER_continue;
					}
				}
				return matchPos - 1;
OUTER_continue: ;
			}
OUTER_break: ;
			return -1;
		}