common/src/main/java/HTTPClient/Util.java
/**
     * Search for a string. Use compile_search() to first generate the second
     * argument. This uses a Knuth-Morris-Pratt like algorithm.
     *
     * @param search  the string to search for.
     * @param cmp     the the array returned by compile_search.
     * @param str     the string in which to look for <var>search</var>.
     * @param beg     the position at which to start the search in
     *                <var>str</var>.
     * @param end     the position at which to end the search in <var>str</var>,
     *                noninclusive.
     * @return the position in <var>str</var> where <var>search</var> was
     *         found, or -1 if not found.
     */
Search for a string. Use compile_search() to first generate the second
argument. This uses a Knuth-Morris-Pratt like algorithm.

@param search  the string to search for.
@param cmp     the the array returned by compile_search.
@param str     the string in which to look for search.
@param beg     the position at which to start the search in
str.
@param end     the position at which to end the search in str,
noninclusive.
@return the position in str where search was
found, or -1 if not found.
Search for a string . Use compile_search () to first generate the second argument . This uses a Knuth - Morris - Pratt like algorithm . @param search the string to search for . @param cmp the the array returned by compile_search . @param str the string in which to look for search . @param beg the position at which to start the search in str . @param end the position at which to end the search in str noninclusive . @return the position in str where search was found or - 1 if not found .
final static int findStr(byte[] search, int[] cmp, byte[] str,
				     int beg, int end)
    {
	int c1f  = cmp[0],
	    c1l  = cmp[1],
	    d1   = c1l - c1f,
	    c2f  = cmp[2],
	    c2l  = cmp[3],
	    d2   = c2l - c2f,
	    c3f  = cmp[4],
	    c3l  = cmp[5],
	    d3   = c3l - c3f;
	Find: while (beg+search.length <= end)
	{
	    if (search[c1l] == str[beg+c1l])
	    {
		/* This is correct, but Visual J++ can't cope with it...
		Comp: if (search[c1f] == str[beg+c1f])
		{
		    for (int idx=0; idx<search.length; idx++)
			if (search[idx] != str[beg+idx])  break Comp;
		    break Find;		
		}
		*  so here is the replacement: */
		if (search[c1f] == str[beg+c1f])
		{
		    boolean same = true;
		    for (int idx=0; idx<search.length; idx++)
			if (search[idx] != str[beg+idx])
			{
				same = false;
				break;
			}
		    if (same)
			break Find;         
		}
		beg += d1;
	    }
	    else if (search[c2l] == str[beg+c2l])
		beg += d2;
	    else if (search[c3l] == str[beg+c3l])
		beg += d3;
	    else
		beg++;
	}
	if (beg+search.length > end)
	    return -1;
	else
	    return beg;
    }
final static int findStr ( byte [ ] search , int [ ] cmp , byte [ ] str , int beg , int end ) { int c1f = cmp [ 0 ] , c1l = cmp [ 1 ] , d1 = c1l - c1f , c2f = cmp [ 2 ] , c2l = cmp [ 3 ] , d2 = c2l - c2f , c3f = cmp [ 4 ] , c3l = cmp [ 5 ] , d3 = c3l - c3f ; Find : while ( beg + search . length <= end ) { if ( search [ c1l ] == str [ beg + c1l ] ) { /* This is correct, but Visual J++ can't cope with it...
		Comp: if (search[c1f] == str[beg+c1f])
		{
		    for (int idx=0; idx<search.length; idx++)
			if (search[idx] != str[beg+idx])  break Comp;

		    break Find;		// we found it
		}
		*  so here is the replacement: */ if ( search [ c1f ] == str [ beg + c1f ] ) { boolean same = true ; for ( int idx = 0 ; idx < search . length ; idx ++ ) if ( search [ idx ] != str [ beg + idx ] ) { same = false ; break ; } if ( same ) break Find ; } beg += d1 ; } else if ( search [ c2l ] == str [ beg + c2l ] ) beg += d2 ; else if ( search [ c3l ] == str [ beg + c3l ] ) beg += d3 ; else beg ++ ; } if ( beg + search . length > end ) return - 1 ; else return beg ; }
Search for a string.
Search for a string .
// we found it