string_nocasestr.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * string_nocasestr.c
  3. *
  4. * Find a string within another string in a case insensitive manner
  5. */
  6. #include "private.h"
  7. #include "lub/ctype.h"
  8. /*--------------------------------------------------------- */
  9. const char *
  10. lub_string_nocasestr(const char *cs,
  11. const char *ct)
  12. {
  13. const char *p = NULL;
  14. const char *result = NULL;
  15. while(*cs)
  16. {
  17. const char *q = cs;
  18. p = ct;
  19. /*lint -e155 Ignoring { }'ed sequence within an expression, 0 assumed
  20. * MACRO implementation uses braces to prevent multiple increments
  21. * when called.
  22. */
  23. /*lint -e506 Constant value Boolean
  24. * not the case because of tolower() evaluating to 0 under lint
  25. * (see above)
  26. */
  27. while(*p && *q && (lub_ctype_tolower(*p) == lub_ctype_tolower(*q)))
  28. {
  29. p++,q++;
  30. }
  31. if(0 == *p)
  32. {
  33. break;
  34. }
  35. cs++;
  36. }
  37. if(p && !*p)
  38. {
  39. /* we've found the first match of ct within cs */
  40. result = cs;
  41. }
  42. return result;
  43. }
  44. /*--------------------------------------------------------- */