🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
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.

45 lines
853 B

  1. #include "config.h"
  2. #include "alstring.h"
  3. #include <cctype>
  4. #include <string>
  5. namespace {
  6. int to_upper(const char ch)
  7. {
  8. using char8_traits = std::char_traits<char>;
  9. return std::toupper(char8_traits::to_int_type(ch));
  10. }
  11. } // namespace
  12. namespace al {
  13. int strcasecmp(const char *str0, const char *str1) noexcept
  14. {
  15. do {
  16. const int diff{to_upper(*str0) - to_upper(*str1)};
  17. if(diff < 0) return -1;
  18. if(diff > 0) return 1;
  19. } while(*(str0++) && *(str1++));
  20. return 0;
  21. }
  22. int strncasecmp(const char *str0, const char *str1, std::size_t len) noexcept
  23. {
  24. if(len > 0)
  25. {
  26. do {
  27. const int diff{to_upper(*str0) - to_upper(*str1)};
  28. if(diff < 0) return -1;
  29. if(diff > 0) return 1;
  30. } while(--len && *(str0++) && *(str1++));
  31. }
  32. return 0;
  33. }
  34. } // namespace al