How to complex switch?

dennis luehring dl.soluz at gmx.net
Thu May 12 05:35:24 PDT 2011


Am 12.05.2011 14:21, schrieb Matthew Ong:
> @dennis luehring
----------------------------------------------------------------
> if (match(str, regex("abc|def|as+b?")) {
>     s1();
> }else if (match(str, regex("za+|wd?|aaa")){ // a lot of () and | ... might have
> missed out one of them
>     s2();
> }else{
>     s3()
> }

ok, but how many times you suffering of masses of this code - and what 
happens if (normaly) your regex matches aren't enough - more states come 
in for example

if (match(str, regex("abc|def|as+b?") && BLUB || BLA ... )
{
     s1();
}else if (match(str, regex("za+|wd?|aaa")){
...

then your switches getting more and more unreadable - your will seperate 
bool algeb. into some helper variables - like this

bool special_active = match(str, regex("abc|def|as+b?") && BLUB || BLA;

if ( special_ative )
{
     s1();
}else if (...){
...

so is see a little help in trivial cases but it won't solve any big 
problem out there


More information about the Digitalmars-d mailing list