]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
glib-2.0: Add string.last_index_of
authorJürg Billeter <j@bitron.ch>
Thu, 20 Jan 2011 21:08:41 +0000 (22:08 +0100)
committerJürg Billeter <j@bitron.ch>
Thu, 20 Jan 2011 21:08:41 +0000 (22:08 +0100)
This deprecates string.rstr.

vapi/glib-2.0.vapi

index 5ea94db408913ef8189be6cbf2aa42115e3cd3eb..628192b88e357707521592fdcadf5347f1e5a5d1 100644 (file)
@@ -958,6 +958,7 @@ public class string {
        [Deprecated (replacement = "string.index_of")]
        [CCode (cname = "strstr")]
        public unowned string? str (string needle);
+       [Deprecated (replacement = "string.last_index_of")]
        [CCode (cname = "g_strrstr")]
        public unowned string? rstr (string needle);
        [CCode (cname = "g_strrstr_len")]
@@ -965,6 +966,8 @@ public class string {
 
        [CCode (cname = "strstr")]
        static char* strstr (char* haystack, char* needle);
+       [CCode (cname = "g_strrstr")]
+       static char* strrstr (char* haystack, char* needle);
        [CCode (cname = "g_utf8_strchr")]
        static char* utf8_strchr (char* str, ssize_t len, unichar c);
 
@@ -978,6 +981,16 @@ public class string {
                }
        }
 
+       public int last_index_of (string needle, int start_index = 0) {
+               char* result = strrstr ((char*) this + start_index, (char*) needle);
+
+               if (result != null) {
+                       return (int) (result - (char*) this);
+               } else {
+                       return -1;
+               }
+       }
+
        public int index_of_char (unichar c, int start_index = 0) {
                char* result = utf8_strchr ((char*) this + start_index, -1, c);