Testing CStrings for equality, ignoring case.

It's amazing to me that such a simple function doesn't exist within the standard library or the STL ( If I'm mistaken, feel free to leave a comment and correct me. ). And who wants to use anything OS or implementation-specific when you shouldn't have to?

Hopefully that will be addressed in the future.

For now, feel free to use these two familiarly named functions "strncasecmp and strcasecmp" if you like. :)
Note that you may need to rename them, as some standard library implementations have them in the cstring header.

#include <locale>
 
template<class CharT>
int strncasecmp(const CharT* s1, const CharT* s2, std::size_t size, const std::locale& loc = std::cout.getloc()) {
	const std::ctype<CharT>& type = std::use_facet<std::ctype<CharT> > (loc);
	int result;
 
	while (size-- > 0 && ( result = type.tolower(*s1) - type.tolower(*s2) ) == 0 && *s1)
		;
 
	return result;
}
 
template<class CharT>
int strcasecmp(const CharT* s1, const CharT* s2, const std::locale& loc = std::cout.getloc()) {
	const std::ctype<CharT>& type = std::use_facet<std::ctype<CharT> > (loc);
	int result;
 
	while (( result = type.tolower(*(s1++)) - type.tolower(*(s2++)) ) == 0 && *s1)
		;
 
	return result;
}

Comments

Valium

Phentermine

Viagra

Xanax

Xanax

Ativan

Cialis

Cialis

Buy Ambien

Viagra

Ambien

RFIRwzDG

xDbzefhp RFIRwzDG

Viagra

Valium

oeGuqkvU

XjezLdr oeGuqkvU