CI_Traits - DryPerspective/C_Builder_Extras GitHub Wiki
A traits class to use with stringlike objects in which comparison is made in a case-insensitive manner. This is a C++ tool as old as time, but having a formal implementation stored away never hurts. Class dp::ci_traits<T> is the class to use as a template parameter in classes such as std::basic_string and std::basic_string_view in order for comparison to be performed in a case-insensitive manner. The header also includes the usual typedefs one would expect for easy use, and a function dp::traits_cast to convert one stringlike which uses one set of traits to one which uses another set of traits. At present this class only supports char and wchar_t traits; and all objects are found in namespace dp.
ci_traits<T> |
A character traits class which allows for case-insensitive comparison |
ci_char_traitsci_wchar_traits
|
Typedefs for ci_traits<char> and ci_traits<wchar_t>, which may prove useful in C++98 to avoid the improper parsing of closing template braces. |
traits_cast |
A function which accepts a stringlike of one set of traits, and returns that stringlike with the same content but another set of traits. |
ci_stringci_wstring
|
Typedefs for std::basic_string<char, ci_traits<char> > and std::basic_string<wchar_t, ci_traits<wchar_t> > respectively. |
ci_string_viewci_wstring_view
|
If std::string_view is available, these are typedefs for std::basic_string_view<char, ci_traits<char> > and std::basic_string_view<wchar_t, ci_traits<wchar_t> > respectively.If not, then they are typedefs for my class dp::basic_string_view with the same template parameters for each. dp::basic_string_view is not a dependency of this header. |
void use_string(std::string_view in_str){
//Make a case-insensitive view
auto in_ci = dp::traits_cast<ci_char_traits>(in_str);
//Perform comparison in case-insensitive way
if(in_ci == "ABORT") return;
//Continue with function below....
}