/* * Case-insensitive string equality * Last modification on 2013-03-21 * * Based on "How to do case-insensitive string comparison" * By Matt Austern * http://lafstern.org/matt/col2_new.pdf */ #ifndef EQSTR_H #define EQSTR_H #include #include #include #include #include struct eq_str : std::binary_function { struct eq_char : std::binary_function { const char *tab; eq_char(const char *t) : tab(t) { } bool operator()(char x, char y) const { return this->tab[x - CHAR_MIN] == this->tab[y - CHAR_MIN]; } }; char tab[CHAR_MAX - CHAR_MIN + 1]; eq_str(const std::locale &L = std::locale::classic()) { for (int i = CHAR_MIN; i <= CHAR_MAX; ++i) this->tab[i - CHAR_MIN] = static_cast(i); std::use_facet >(L).toupper(this->tab, this->tab + (CHAR_MAX - CHAR_MIN + 1)); } bool operator()(const std::string &x, const std::string &y) const { return x.length() == y.length() && std::equal(x.begin(), x.end(), y.begin(), eq_char(this->tab)); } }; #endif