Re: Caseless String
Le Chaud Lapin wrote:
Le Chaud Lapin wrote:
so I guess at this point I will
retreat, work with my code, and come up with some concrete examples
that I can present for discussion.
Thanks so far...
Update:
After some fiddling, at least it seems that it is possible to have a
caseless string. I don't have the same knid of warm and fuzzy that
I got when developing, say, Priortized_Associative_Set<>, but it's a
start:
My objective was to do caseless string comparisons:
Caseless_String s1 = "Hello";
String s2 = "HeLLo";
s1 == s2; // true.
String s3 = "hEllO";
s1 == s2; // true
s1 == s3; // true
s2 == s3; // false, and CONFUSING
I am not sure, but it seems so far that a way to do this is to not
define caseless strings, but a caseless character class:
Or an ignore-case comparison function. :-)
snip
template <typename C, typename X> inline bool operator == (const
Caseless<C> &c, const X &x) {return toupper(c.c) == toupper(x);}
template <typename C, typename X> inline bool operator != (const
Caseless<C> &c, const X &x) {return toupper(c.c) != toupper(x);}
Here toupper() will only work for a very limited set of characters.
snip
String<Caseless<unsigned int> > s8 = "SALUT LE MONDE."
String<unsigned short> s9 = "Hola, Que Tal?"
String<long double> s10 = s8;
String<int> s11 = s9;
s11 == s9; // True
I would also like a language-less string type, so that
s8 == s9; // true?
Is that possible?
Bo Persson
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]