case_insensitive_char_traits.cpp 838 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "case_insensitive_char_traits.h"
  2. #include "case_insensitive_string.h"
  3. #include <util/string/escape.h>
  4. int TCaseInsensitiveCharTraits::compare(const char* s1, const char* s2, std::size_t n) {
  5. while (n-- != 0) {
  6. if (to_upper(*s1) < to_upper(*s2)) {
  7. return -1;
  8. }
  9. if (to_upper(*s1) > to_upper(*s2)) {
  10. return 1;
  11. }
  12. ++s1;
  13. ++s2;
  14. }
  15. return 0;
  16. }
  17. const char* TCaseInsensitiveCharTraits::find(const char* s, std::size_t n, char a) {
  18. auto const ua(to_upper(a));
  19. while (n-- != 0) {
  20. if (to_upper(*s) == ua)
  21. return s;
  22. s++;
  23. }
  24. return nullptr;
  25. }
  26. TCaseInsensitiveString EscapeC(const TCaseInsensitiveString& str) {
  27. const auto result = EscapeC(str.data(), str.size());
  28. return {result.data(), result.size()};
  29. }