comparing strings

Stephen Webb stephen.webb at cybersafe.com
Tue Feb 15 20:09:34 GMT 2000


On Tue, 15 Feb 2000, you wrote:
> On Tue, 15 Feb 2000, Stephen Webb wrote:
> 
> > On Mon, 14 Feb 2000, you wrote:
> > > On Sun, 13 Feb 2000, Martin Wiebusch wrote:
> > > 
> > > > Hi,
> > > > just a simple question: Is there a method in the string class to compare
> > > > strings without regard to upper/lower case?
> > > 
> > > QString s1="one string";
> > > QString s2="One String";
> > > 
> > > if (s1.lower()==s2.lower())
> > > 	printf ("The strings are equal regardless of case");
> > 
> > Does this take into account localization rules?  For example, both lower-case
> > sigmas in Greek map into a single upper-case sigma.  In German, at least under
> > some rules, the lower case esszed maps into two upper case esses.  Either of
> > these examples might break the above.
> 
> Look that I used lower() not upper() ;-)
> 
> Whether QString's lower() notices that "SS" is one
> lower_case_char_I_can't_type I don't know. Maybe you could, well, check.

Okay, I checked the source. Qt 1.44 did not do things correctly at all.  Qt
2.0.2 supports only ASCII and Unicode as simple 1:1 conversions.  Assuming
you're using Unicode (you're the one?) or a subset, the above comparison will
most likely work most of the time.  Depending on your problem domain, it may
even work all of the time.  I guess chances are if you need a case-insensitive
comparison, you have a small well-defined problem domain anyway.  If you were
doing something like trying to look up a user-entered name in a telephone book
and you want to ignore case and you want it to work in an internationalized
environment, you will end up with a lot of frustrated users, or at least in
some countries.

The XPG4 standard for internationalization supports most of this stuff, but the
Qt libraries are in no way XPG4-compliant.  I imagine that's so they can be
platform independant.


SMW




More information about the KDevelop mailing list