Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cctype>
- #include <string>
- struct ci_char_traits : public std::char_traits<char> {
- static constexpr char_type tolower(char_type symbol) {
- return (symbol >= 65 && symbol <= 90) ? (symbol + 32) : symbol;
- }
- static constexpr bool eq(char_type lhs, char_type rhs) noexcept {
- return tolower(lhs) == tolower(rhs);
- }
- static constexpr bool lt(char_type lhs, char_type rhs) noexcept {
- return tolower(lhs) < tolower(rhs);
- }
- static int compare(const char_type* lhs, const char_type* rhs, std::size_t size) {
- while(size--) {
- if(lt(*lhs, *rhs)) return -1;
- if(lt(*rhs, *lhs)) return 1;
- ++lhs;
- ++rhs;
- }
- return 0;
- }
- static const char_type* find(const char_type* string, std::size_t size, const char_type& symbol) {
- while(size--) {
- if(eq(*string, symbol)) {
- return string;
- }
- ++string;
- }
- return nullptr;
- }
- };
- using ci_string = std::basic_string<char, ci_char_traits>;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement