GNOME Bugzilla – Bug 639586
Negative slice index to end of string
Last modified: 2011-02-28 10:33:15 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
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
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.