1
0

string_nocasestr.c 979 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 *lub_string_nocasestr(const char *cs, const char *ct)
  10. {
  11. const char *p = NULL;
  12. const char *result = NULL;
  13. while (*cs) {
  14. const char *q = cs;
  15. p = ct;
  16. /*lint -e155 Ignoring { }'ed sequence within an expression, 0 assumed
  17. * MACRO implementation uses braces to prevent multiple increments
  18. * when called.
  19. */
  20. /*lint -e506 Constant value Boolean
  21. * not the case because of tolower() evaluating to 0 under lint
  22. * (see above)
  23. */
  24. while (*p && *q
  25. && (lub_ctype_tolower(*p) == lub_ctype_tolower(*q))) {
  26. p++, q++;
  27. }
  28. if (0 == *p) {
  29. break;
  30. }
  31. cs++;
  32. }
  33. if (p && !*p) {
  34. /* we've found the first match of ct within cs */
  35. result = cs;
  36. }
  37. return result;
  38. }
  39. /*--------------------------------------------------------- */