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

James 'Ender' Brown ender at scummvm.org
Sun Jul 23 03:31:45 CEST 2006


> > A single bool, and one extra branch (assuming the default case to  
> > be an
> > insensitive comparison, avoiding a jump) really shouldn't add an
> > excessive overhead.
> 
> I don't see how this would work in general. If I have two strings,  
> one marked as "case insensitive", and one marked as "case sensitive"  
> -- how would they be compared in that model?
> 
> Or do you mean a single "global" flag that switches the comparison  
> mode for *all* strings? No, I won't believe anybody would seriously  
> suggest something like that :-)

A global flag... Hmm, no, it wouldn't be that useful :)

Now you bring it up, this does complicate things in terms of
order-of-operation... A Stringi subclass (or a Stringc subclass) for
insensitive/case-sensitive matches appears to be more sensible on
second-thought. 

I was suggesting something like:
	String a = "I like cheese";
	String b = "I like cheese";

	a.setCaseSensitive();
	if (a == b) {
		return true;
        }

	bool String::operator ==(const String &x) const {
		if (!caseSensitive)
		        return (0 == scumm_strnicmp(c_str(),x.c_str()));
	        return (0 == strcmp(c_str(), x.c_str()));
	}

Cheers,
	Ender


> 
> Cheers,
> Max
> 
> 
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys -- and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Scummvm-devel mailing list
> Scummvm-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/scummvm-devel
-- 
James 'Ender' Brown <ender at scummvm.org>





More information about the Scummvm-devel mailing list