case_insensitive_char_traits.h 781 B

123456789101112131415161718192021222324252627282930
  1. #pragma once
  2. #include <contrib/libs/libc_compat/string.h>
  3. #include <string>
  4. struct TCaseInsensitiveCharTraits : private std::char_traits<char> {
  5. static bool eq(char c1, char c2) {
  6. return to_upper(c1) == to_upper(c2);
  7. }
  8. static bool lt(char c1, char c2) {
  9. return to_upper(c1) < to_upper(c2);
  10. }
  11. static int compare(const char* s1, const char* s2, std::size_t n);
  12. static const char* find(const char* s, std::size_t n, char a);
  13. using std::char_traits<char>::assign;
  14. using std::char_traits<char>::char_type;
  15. using std::char_traits<char>::copy;
  16. using std::char_traits<char>::length;
  17. using std::char_traits<char>::move;
  18. private:
  19. static char to_upper(char ch) {
  20. return std::toupper((unsigned char)ch);
  21. }
  22. };