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 639586 - Negative slice index to end of string
Negative slice index to end of string
Status: RESOLVED NOTABUG
Product: vala
Classification: Core
Component: general
0.11.x
Other Linux
: Normal enhancement
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2011-01-15 07:17 UTC by Justin Willmert
Modified: 2011-02-28 10:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
glib-2.0: Support for Negative slice index to end of string (805 bytes, patch)
2011-01-31 18:44 UTC, Marco Trevisan (Treviño)
none Details | Review

Description Justin Willmert 2011-01-15 07:17:51 UTC
Could the slicing operation be fixed/upgraded to work like the substring method for strings? For example

    string teststring = "somepath/somefile.so";
    print(teststring.substring(-3));

will produce the output ".so". Using slices, a -1 index would cut off the "o". E.g.

    print(teststring[-3:-1]);

produces the output ".s". Using a slice ending at 0, though,

    print(teststring[-3:0]);

gives the runtime errors:

    ** (process:16492): CRITICAL **: string_slice: assertion `start <= end' failed
Comment 1 Marco Trevisan (Treviño) 2011-01-31 18:44:38 UTC
Created attachment 179736 [details] [review]
glib-2.0: Support for Negative slice index to end of string

Ok, this small patch for glib-2.0 vapi fixes the issue
Comment 2 Luca Bruno 2011-02-28 10:33:15 UTC
You're looking for teststring[-3:teststring.length]. Negative indexes means starting from the end backward, positive indexes are normal indexes from the start forward. A syntax like teststring[-3:] (meaning teststring[-3:teststring.length]) could be supported instead, which is pretty much different than teststring[-3:0].
Thanks for taking the time to report the bug. Closing as not a bug.