Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.6 KiB

  1. #include "precomp.hxx"
  2. #define DLL_IMPLEMENTATION
  3. #define IMPLEMENTATION_EXPORT
  4. #include <irtlmisc.h>
  5. // stristr (stolen from fts.c, wickn)
  6. //
  7. // case-insensitive version of strstr.
  8. // stristr returns a pointer to the first occurrence of
  9. // pszSubString in pszString. The search does not include
  10. // terminating nul characters.
  11. //
  12. // NOTE: This routine is NOT DBCS-safe?
  13. const char*
  14. stristr(const char* pszString, const char* pszSubString)
  15. {
  16. const char *cp1 = (const char*) pszString, *cp2, *cp1a;
  17. char first;
  18. // get the first char in string to find
  19. first = pszSubString[0];
  20. // first char often won't be alpha
  21. if (isalpha((UCHAR)first))
  22. {
  23. first = (char) tolower(first);
  24. for ( ; *cp1 != '\0'; cp1++)
  25. {
  26. if (tolower(*cp1) == first)
  27. {
  28. for (cp1a = &cp1[1], cp2 = (const char*) &pszSubString[1];
  29. ;
  30. cp1a++, cp2++)
  31. {
  32. if (*cp2 == '\0')
  33. return cp1;
  34. if (tolower(*cp1a) != tolower(*cp2))
  35. break;
  36. }
  37. }
  38. }
  39. }
  40. else
  41. {
  42. for ( ; *cp1 != '\0' ; cp1++)
  43. {
  44. if (*cp1 == first)
  45. {
  46. for (cp1a = &cp1[1], cp2 = (const char*) &pszSubString[1];
  47. ;
  48. cp1a++, cp2++)
  49. {
  50. if (*cp2 == '\0')
  51. return cp1;
  52. if (tolower(*cp1a) != tolower(*cp2))
  53. break;
  54. }
  55. }
  56. }
  57. }
  58. return NULL;
  59. }