D
Diego Martins
Hi! The following code snippet:
namespace {
bool charCompare(char a, char b) {
return tolower(a) < tolower(b);
}
}
bool compareString(const std::string & s1, const std::string & s2)
{
return
std::lexicographical_compare(s1.begin(),s1.end(),s2.begin(),s2.end(),charCompare);
}
presents a compareString function to compare strings ignoring the case
compareString("yes","YES") --> true;
but
compareString("ahá","AHÁ") --> false;
how can I make it more portable to using accents, for example?
what are your background in this issue? what about using a Locale
class? (actually, I know nothing about locales in C++)
a possible idea is using classes to deal with character encode.
something like that:
compareString<ISO8859_1>("ahá","AHÁ")
and it will delegate to charCompare<T>
an alternative is to use an overload like that:
bool compareString(const std::string & s1, const std::string & s2,
const CharConv & conv)
and CharConv can be a conversion table or a class that implements
tolower() and toupper() for each desired character codification
can you comment the ideas above?
any better ideas?
Diego Martins
HP
namespace {
bool charCompare(char a, char b) {
return tolower(a) < tolower(b);
}
}
bool compareString(const std::string & s1, const std::string & s2)
{
return
std::lexicographical_compare(s1.begin(),s1.end(),s2.begin(),s2.end(),charCompare);
}
presents a compareString function to compare strings ignoring the case
compareString("yes","YES") --> true;
but
compareString("ahá","AHÁ") --> false;
how can I make it more portable to using accents, for example?
what are your background in this issue? what about using a Locale
class? (actually, I know nothing about locales in C++)
a possible idea is using classes to deal with character encode.
something like that:
compareString<ISO8859_1>("ahá","AHÁ")
and it will delegate to charCompare<T>
an alternative is to use an overload like that:
bool compareString(const std::string & s1, const std::string & s2,
const CharConv & conv)
and CharConv can be a conversion table or a class that implements
tolower() and toupper() for each desired character codification
can you comment the ideas above?
any better ideas?
Diego Martins
HP