const PRUnichar *searchBuf = searchStr.get(); const PRUnichar *patternBuf = patternStr.get();
const PRUnichar *searchBuf = aSearchStr.get(); const PRUnichar *patternBuf = aPatternStr.get();
static PRInt32 FindInString(const nsString &searchStr, const nsString &patternStr,                            PRInt32 startOffset, PRBool searchBackwards){  PRInt32 foundOffset = -1;  PRInt32 patternLen = patternStr.Length();  PRInt32 searchStrLen = searchStr.Length();  if (patternLen == 0) // pattern is empty    return -1;  if (startOffset < 0)    startOffset = (searchBackwards) ? searchStrLen : 0;  if (startOffset > searchStrLen) // bad start offset    return -1;  if (patternLen > searchStrLen) // pattern is longer than string to search    return -1;  const PRUnichar *searchBuf = searchStr.get();  const PRUnichar *patternBuf = patternStr.get();  const PRUnichar *searchEnd = searchBuf + searchStrLen;  const PRUnichar *patEnd = patternBuf + patternLen;  if (searchBackwards)  {    // searching backwards    const PRUnichar *s = searchBuf + startOffset - patternLen;    while (s >= searchBuf)    {      if (CharsMatch(*patternBuf, *s)) // start potential match      {        const PRUnichar *t = s;        const PRUnichar *p = patternBuf;        PRInt32 curMatchOffset = t - searchBuf;        PRBool inWhitespace = nsCRT::IsAsciiSpace(*p);          while (p < patEnd && CharsMatch(*p, *t))        {          if (inWhitespace && !nsCRT::IsAsciiSpace(*p))          {            // leaving p whitespace. Eat up addition whitespace in s            while (t < searchEnd - 1 && nsCRT::IsAsciiSpace(*(t + 1)))              t ++;            inWhitespace = PR_FALSE;          }          else           inWhitespace = nsCRT::IsAsciiSpace(*p);          t ++;          p ++;        }          if (p == patEnd)        {          foundOffset = curMatchOffset;          goto done;        }          // could be smart about decrementing s here      }      s --;    }  }  else  {    // searching forwards    const PRUnichar *s = &searchBuf[startOffset];    while (s < searchEnd)    {      if (CharsMatch(*patternBuf, *s)) // start potential match      {        const PRUnichar *t = s;        const PRUnichar *p = patternBuf;        PRInt32 curMatchOffset = t - searchBuf;        PRBool inWhitespace = nsCRT::IsAsciiSpace(*p);        while (p < patEnd && CharsMatch(*p, *t))        {          if (inWhitespace && !nsCRT::IsAsciiSpace(*p))          {            // leaving p whitespace. Eat up addition whitespace in s            while (t < searchEnd - 1 && nsCRT::IsAsciiSpace(*t))              t ++;            inWhitespace = PR_FALSE;          }          else            inWhitespace = nsCRT::IsAsciiSpace(*p);          t ++;          p ++;        }        if (p == patEnd)        {          foundOffset = curMatchOffset;          goto done;        }        // could be smart about incrementing s here      }      s ++;    }  }done:  return foundOffset;}