str.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 2k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "npcommon.h"
  2. // strstrf(str, srch)
  3. //
  4. // Returns a pointer to the first occurrence of srch within
  5. // str (like strchrf, but search parameter is a string, not
  6. // a single character).  Returns NULL if not found.
  7. // REVIEW: simple algorithm here, but depending on usage,
  8. // might be overkill to complicate it.
  9. LPSTR WINAPI strstrf(LPCSTR lpString, LPCSTR lpSearch)
  10. {
  11.     INT cbSearch = strlenf(lpSearch);
  12.     INT cbToSearch;
  13.     LPSTR lp;
  14.     // calculate the maximum distance to go -- the length
  15.     // of the string to look in less the length of the
  16.     // string to search for, since beyond that the string
  17.     // being searched for would not fit.
  18.     cbToSearch = strlenf(lpString) - cbSearch;
  19.     if (cbToSearch < 0)
  20.         return NULL;    /* string being searched is shorter */
  21.     for (lp = (LPSTR)lpString; lp - lpString <= cbToSearch; ADVANCE(lp)) {
  22.         if (strncmpf(lp, lpSearch, cbSearch) == 0)
  23.             return lp;
  24.     }
  25.     return NULL;
  26. }
  27. // stristrf(str, srch)
  28. //
  29. // Returns a pointer to the first occurrence of srch within
  30. // str, case-insensitive.  Returns NULL if not found.
  31. // REVIEW: simple algorithm here, but depending on usage,
  32. // might be overkill to complicate it.
  33. LPSTR WINAPI stristrf(LPCSTR lpString, LPCSTR lpSearch)
  34. {
  35.     INT cbSearch = strlenf(lpSearch);
  36.     INT cbToSearch;
  37.     LPSTR lp;
  38.     // calculate the maximum distance to go -- the length
  39.     // of the string to look in less the length of the
  40.     // string to search for, since beyond that the string
  41.     // being searched for would not fit.
  42.     cbToSearch = strlenf(lpString) - cbSearch;
  43.     if (cbToSearch < 0)
  44.         return NULL;    /* string being searched is shorter */
  45.     for (lp = (LPSTR)lpString; lp - lpString <= cbToSearch; ADVANCE(lp)) {
  46.         if (strnicmpf(lp, lpSearch, cbSearch) == 0)
  47.             return lp;
  48.     }
  49.     return NULL;
  50. }