GNOME Bugzilla – Bug 624673
Allow regular expression literals as case labels in switch statements
Last modified: 2018-05-22 13:42:10 UTC
Created attachment 166114 [details] [review] Patch against 0.9.3 to add regex case labels I'm attaching a patch which adds this syntax (borrowed from Ruby), so you can say: var str = "vala"; switch (str) { case "C": print("boring\n"); break; case /^C[+#]+$/: print("still boring\n"); break; case /[lv]a[lv]a/: print("OMG LAVA! RUN!\n"); break; } Or in Genie: case name when "luser": print "bofh!" when "loser": print "i'm offended!" when /loo+ser/: print "pls lern 2 spel!"
What will happen when two regexes both match the string?
(In reply to comment #1) > What will happen when two regexes both match the string? Then it will fall into the section associated with the first of the two regexes.
I'm not sure whether this is not too implicit. Is an explicit if/elseif cascade so much worse?
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/122.