if (NS_FAILED(pipe->mCondition)) { return pipe->mCondition; }
nsPipe::nsPipeInputStream::Search(const char *forString,                                   PRBool ignoreCase,                                  PRBool *found,                                  PRUint32 *offsetSearchedTo){    nsPipe* pipe = GET_INPUTSTREAM_PIPE(this);    if (NS_FAILED(pipe->mCondition)) {        return pipe->mCondition;    }    nsresult rv;    const char* bufSeg1;    PRUint32 bufSegLen1;    PRUint32 segmentPos = 0;    PRUint32 strLen = nsCRT::strlen(forString);    rv = pipe->GetReadSegment(segmentPos, &bufSeg1, &bufSegLen1);    if (NS_FAILED(rv) || bufSegLen1 == 0) {        *found = PR_FALSE;        *offsetSearchedTo = segmentPos;        return NS_OK;    }    while (PR_TRUE) {        PRUint32 i;        // check if the string is in the buffer segment        for (i = 0; i < bufSegLen1 - strLen + 1; i++) {            if (COMPARE(&bufSeg1[i], forString, strLen) == 0) {                *found = PR_TRUE;                *offsetSearchedTo = segmentPos + i;                return NS_OK;            }        }        // get the next segment        const char* bufSeg2;        PRUint32 bufSegLen2;        segmentPos += bufSegLen1;        rv = pipe->GetReadSegment(segmentPos, &bufSeg2, &bufSegLen2);        if (NS_FAILED(rv) || bufSegLen2 == 0) {            *found = PR_FALSE;            if (pipe->mCondition != NS_OK)    // XXX NS_FAILED?                *offsetSearchedTo = segmentPos - bufSegLen1;            else                *offsetSearchedTo = segmentPos - bufSegLen1 - strLen + 1;            return NS_OK;        }        // check if the string is straddling the next buffer segment        PRUint32 limit = PR_MIN(strLen, bufSegLen2 + 1);        for (i = 0; i < limit; i++) {            PRUint32 strPart1Len = strLen - i - 1;            PRUint32 strPart2Len = strLen - strPart1Len;            const char* strPart2 = &forString[strLen - strPart2Len];            PRUint32 bufSeg1Offset = bufSegLen1 - strPart1Len;            if (COMPARE(&bufSeg1[bufSeg1Offset], forString, strPart1Len) == 0 &&                COMPARE(bufSeg2, strPart2, strPart2Len) == 0) {                *found = PR_TRUE;                *offsetSearchedTo = segmentPos - strPart1Len;                return NS_OK;            }        }        // finally continue with the next buffer        bufSeg1 = bufSeg2;        bufSegLen1 = bufSegLen2;    }    NS_NOTREACHED("can't get here");    return NS_ERROR_FAILURE;    // keep compiler happy}