[Lazarus] Easiest way to "case" strings

Michael Van Canneyt michael at freepascal.org
Sat Mar 21 16:24:02 CET 2009



On Sat, 21 Mar 2009, Flávio Etrusco wrote:

> >>
> >> Can anyone say why there is no string case statement in Object Pascal?  I've
> >> always wondered about this as sometimes it hard to avoid 10-20 If..then..else
> >> if.... statements.
> >>
> >> Would the compiled code of a string case statement even be any more efficient or
> >> is the benefit mostly in code readability?
> >
> > In the case of strings, it would mostly be code readability. For ordinal
> > types, a case statement can be optimized using jump tables.
> >
> > Michael.
> 
> A string case could be optimized with compile-time hashes or something else.

Even so, there are some serious issues with a string 'case' as a language construct:
- What about encodings ? 
- Should it be case sensitive or not ? 
I don't think that these can be solved in a satisfying manner on a language level.

Michael.


More information about the Lazarus mailing list