aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/case_insensitive_string/case_insensitive_char_traits.h
blob: 2717893c10273803856c5ae7547ee336741be558 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#pragma once

#include <contrib/libs/libc_compat/string.h>

#include <string>

struct TCaseInsensitiveCharTraits : private std::char_traits<char> {
    static bool eq(char c1, char c2) {
        return to_upper(c1) == to_upper(c2);
    }

    static bool lt(char c1, char c2) {
        return to_upper(c1) < to_upper(c2);
    }

    static int compare(const char* s1, const char* s2, std::size_t n);

    static const char* find(const char* s, std::size_t n, char a);

    using std::char_traits<char>::assign;
    using std::char_traits<char>::char_type;
    using std::char_traits<char>::copy;
    using std::char_traits<char>::length;
    using std::char_traits<char>::move;

private:
    static char to_upper(char ch) {
        return std::toupper((unsigned char)ch);
    }
};