Created
May 14, 2013 03:16
-
-
Save kingsamchen/5573414 to your computer and use it in GitHub Desktop.
user_defined stl::basic_string traits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using std::basic_string; | |
using std::char_traits; | |
using std::string; | |
using std::toupper;; | |
struct ichar_traits : char_traits<char> | |
{ | |
static bool eq(const char& _Left, const char& _Right) | |
{ | |
return toupper(_Left) == toupper(_Right); | |
} | |
static bool lt(const char& _Left, const char& _Right) | |
{ | |
return toupper(_Left) < toupper(_Right); | |
} | |
static int compare(const char_type* _Str1, const char_type* _Str2, size_t _Num ) | |
{ | |
const char_type* ps1 = _Str1; | |
const char_type* ps2 = _Str2; | |
for (size_t i = 0; i < _Num; ++i) | |
{ | |
if (ps1 == NULL) | |
{ | |
return -1; | |
} | |
else if (ps2 == NULL) | |
{ | |
return 1; | |
} | |
else if (toupper(*ps1) < toupper(*ps2)) | |
{ | |
return -1; | |
} | |
else if (toupper(*ps1) > toupper(*ps2)) | |
{ | |
return 1; | |
} | |
assert(toupper(*ps1) == toupper(*ps2)); | |
++ps1; | |
++ps2; | |
} | |
return 0; | |
} | |
}; | |
typedef basic_string<char, ichar_traits> istring; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment