[vala] glib-2.0: Add string.index_of_char



commit df95dc3a1ae870cadbbbeb2ca9bfeb2805159a28
Author: Jürg Billeter <j bitron ch>
Date:   Sat Jan 15 21:16:09 2011 +0100

    glib-2.0: Add string.index_of_char
    
    This deprecates string.chr.

 vapi/glib-2.0.vapi          |   13 +++++++++++++
 vapigen/valagidlparser.vala |   10 +++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index b5fe72c..5deec50 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -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")]
diff --git a/vapigen/valagidlparser.vala b/vapigen/valagidlparser.vala
index ccc6e4f..16c95db 100644
--- a/vapigen/valagidlparser.vala
+++ b/vapigen/valagidlparser.vala
@@ -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;
 				}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]