[Scummvm-devel] Make class String case insensitive by default?

Max Horn max at quendi.de
Sun Jul 23 17:10:31 CEST 2006


Am 23.07.2006 um 15:53 schrieb Marcus Comstedt:

>
> "Johannes Schickel" <lordhoto at gmail.com> writes:
>
>> I thought of adding one bool which is used for the mode to use, this
>> would of course need branching for every comparison function, but it
>> shouldn't be that slow nor a big waste of memory.
>
> 4 bytes per string adds up if there are many strings.

Indeed.

>   The subclass
> proposal is better as it relies on the vtable field which is already
> there.  Also it is less error prone as you don't add extra state to
> the strings which needs to be maintained.

Aye. Though it doesn't solve the problem of how to deal with  
comparing a "sensitive" string with an "insensitive one" (of course  
you never said it would). In particular, if not done careful, then
  a == b
and
  b == a
might return different values, which would be a big no-no.


> Even so, I agree with Oystein that sensitivity should be a property of
> the comparison, not the string.

So do I. Personally, I'd add
	bool equals(const String &x) const;
	bool equalsIgnoreCase(const String &x) const;
	bool compareTo(const String &x) const;
	bool compareToIgnoreCase(const String &x) const;
methods (those names are taken from Java, and of course don't quite  
fit in; this is just a quick example), as others already suggested.

It really just boils down to the default behavior of == and != (i.e.  
to which of the above methods do they map). I just run a check on the  
code to find all places where String's comparison operators are used.  
In virtually all places, ignoring the case should be perfectly fine  
and safe.


Bye,
Max





More information about the Scummvm-devel mailing list