case_insensitive_char_traits.cpp 905 B

1234567891011121314151617181920212223242526272829303132
  1. #include "case_insensitive_char_traits.h"
  2. #include <util/string/escape.h>
  3. template <typename TImpl>
  4. const char* ::NPrivate::TCommonCaseInsensitiveCharTraits<TImpl>::find(const char* s, std::size_t n, char a) {
  5. const auto ca(TImpl::ToCommonCase(a));
  6. while (n-- != 0) {
  7. if (TImpl::ToCommonCase(*s) == ca)
  8. return s;
  9. s++;
  10. }
  11. return nullptr;
  12. }
  13. int TCaseInsensitiveCharTraits::compare(const char* s1, const char* s2, std::size_t n) {
  14. while (n-- != 0) {
  15. auto c1 = ToCommonCase(*s1), c2 = ToCommonCase(*s2);
  16. if (c1 < c2) {
  17. return -1;
  18. }
  19. if (c1 > c2) {
  20. return 1;
  21. }
  22. ++s1;
  23. ++s2;
  24. }
  25. return 0;
  26. }
  27. template struct ::NPrivate::TCommonCaseInsensitiveCharTraits<TCaseInsensitiveCharTraits>;
  28. template struct ::NPrivate::TCommonCaseInsensitiveCharTraits<TCaseInsensitiveAsciiCharTraits>;