After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 624673 - Allow regular expression literals as case labels in switch statements
Allow regular expression literals as case labels in switch statements
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Control Flow Statements
0.9.x
Other All
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2010-07-18 15:35 UTC by carlo.teubner
Modified: 2018-05-22 13:42 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch against 0.9.3 to add regex case labels (8.42 KB, patch)
2010-07-18 15:35 UTC, carlo.teubner
none Details | Review

Description carlo.teubner 2010-07-18 15:35:41 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!"
Comment 1 zarevucky.jiri 2010-07-18 16:04:07 UTC
What will happen when two regexes both match the string?
Comment 2 carlo.teubner 2010-07-18 16:16:49 UTC
(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.
Comment 3 Michael 'Mickey' Lauer 2011-03-03 15:42:21 UTC
I'm not sure whether this is not too implicit. Is an explicit if/elseif cascade so much worse?
Comment 4 GNOME Infrastructure Team 2018-05-22 13:42:10 UTC
-- 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.