]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
glib-2.0: Add string.index_of_char
authorJürg Billeter <j@bitron.ch>
Sat, 15 Jan 2011 20:16:09 +0000 (21:16 +0100)
committerJürg Billeter <j@bitron.ch>
Sat, 15 Jan 2011 20:17:35 +0000 (21:17 +0100)
This deprecates string.chr.

vapi/glib-2.0.vapi
vapigen/valagidlparser.vala

index b5fe72c2567f8c6b8003964d2986181c6b5f9309..5deec50f0cb1ceed224f537d38e6b8feba54c8f4 100644 (file)
@@ -965,6 +965,8 @@ public class string {
 
        [CCode (cname = "strstr")]
        static char* strstr (char* haystack, char* needle);
+       [CCode (cname = "g_utf8_strchr")]
+       static char* utf8_strchr (char* str, ssize_t len, unichar c);
 
        public int index_of (string needle, int start_index = 0) {
                char* result = strstr ((char*) this + start_index, (char*) needle);
@@ -976,6 +978,16 @@ public class string {
                }
        }
 
+       public int index_of_char (unichar c, int start_index = 0) {
+               char* result = utf8_strchr ((char*) this + start_index, -1, c);
+
+               if (result != null) {
+                       return (int) (result - (char*) this);
+               } else {
+                       return -1;
+               }
+       }
+
        [CCode (cname = "g_str_has_prefix")]
        public bool has_prefix (string prefix);
        [CCode (cname = "g_str_has_suffix")]
@@ -1052,6 +1064,7 @@ public class string {
        [Deprecated (replacement = "string.length")]
        [CCode (cname = "strlen")]
        public long len ();
+       [Deprecated (replacement = "string.index_of_char")]
        [CCode (cname = "g_utf8_strchr")]
        public unowned string chr (ssize_t len, unichar c);
        [CCode (cname = "g_utf8_strrchr")]
index ccc6e4f6c5c539505dab9cf4cc69c5f8ebdff702..16c95dbec9518ecd8708b1f28f931415cf2b0e75 100644 (file)
@@ -124,7 +124,7 @@ public class Vala.GIdlParser : CodeVisitor {
                                                continue;
                                        }
 
-                                       if (null != tokens[0].chr (-1, '*')) {
+                                       if (-1 != tokens[0].index_of_char ('*')) {
                                                PatternSpec* pattern = new PatternSpec (tokens[0]);
                                                codenode_attributes_patterns[pattern] = tokens[0];
                                        }
@@ -2621,15 +2621,15 @@ public class Vala.GIdlParser : CodeVisitor {
                var attributes = codenode_attributes_map.get (codenode);
 
                if (attributes == null) {
-                       var dot_required = (null != codenode.chr (-1, '.'));
-                       var colon_required = (null != codenode.chr (-1, ':'));
+                       var dot_required = (-1 != codenode.index_of_char ('.'));
+                       var colon_required = (-1 != codenode.index_of_char (':'));
 
                        var pattern_specs = codenode_attributes_patterns.get_keys ();
                        foreach (PatternSpec* pattern in pattern_specs) {
                                var pspec = codenode_attributes_patterns[pattern];
 
-                               if ((dot_required && null == pspec.chr (-1, '.')) ||
-                                   (colon_required && null == pspec.chr (-1, ':'))) {
+                               if ((dot_required && -1 != pspec.index_of_char ('.')) ||
+                                   (colon_required && -1 != pspec.index_of_char (':'))) {
                                        continue;
                                }