[vala] glib-2.0: Use byte indices for strings



commit 84c634b18f2e6f8121aef0172a9034b672de2e32
Author: Jürg Billeter <j bitron ch>
Date:   Fri Aug 20 20:41:27 2010 +0200

    glib-2.0: Use byte indices for strings

 codegen/valaccodearraymodule.vala |    6 ++----
 vapi/glib-2.0.vapi                |   18 ++++++++++--------
 2 files changed, 12 insertions(+), 12 deletions(-)
---
diff --git a/codegen/valaccodearraymodule.vala b/codegen/valaccodearraymodule.vala
index 2eebca7..9242b83 100644
--- a/codegen/valaccodearraymodule.vala
+++ b/codegen/valaccodearraymodule.vala
@@ -415,12 +415,10 @@ public class Vala.CCodeArrayModule : CCodeMethodCallModule {
 			// should be moved to a different module
 
 			// access to unichar in a string
-			var coffsetcall = new CCodeFunctionCall (new CCodeIdentifier ("g_utf8_offset_to_pointer"));
-			coffsetcall.add_argument (ccontainer);
-			coffsetcall.add_argument (cindex);
+			var coffset = new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, ccontainer, cindex);
 
 			var ccall = new CCodeFunctionCall (new CCodeIdentifier ("g_utf8_get_char"));
-			ccall.add_argument (coffsetcall);
+			ccall.add_argument (coffset);
 
 			expr.ccodenode = ccall;
 		} else {
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index de52041..851cfc1 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -970,15 +970,17 @@ public class string {
 	public unichar get_char ();
 	[CCode (cname = "g_utf8_get_char_validated")]
 	public unichar get_char_validated (ssize_t max_len = -1);
-	[CCode (cname = "g_utf8_offset_to_pointer")]
-	public unowned string offset (long offset);
-	[CCode (cname = "g_utf8_pointer_to_offset")]
-	public long pointer_to_offset (string pos);
+	public unowned string offset (long offset) {
+		return (string) ((char*) this + offset);
+	}
+	public long pointer_to_offset (string pos) {
+		return (long) ((char*) pos - (char*) this);
+	}
 	[CCode (cname = "g_utf8_prev_char")]
 	public unowned string prev_char ();
 	[Deprecated (replacement = "string.length")]
-	[CCode (cname = "g_utf8_strlen")]
-	public long len (ssize_t max = -1);
+	[CCode (cname = "strlen")]
+	public long len ();
 	[CCode (cname = "g_utf8_strchr")]
 	public unowned string chr (ssize_t len, unichar c);
 	[CCode (cname = "g_utf8_strrchr")]
@@ -1079,7 +1081,6 @@ public class string {
 
 	[CCode (cname = "g_strdup")]
 	public string dup ();
-	// n is size in bytes, not length in characters
 	[CCode (cname = "g_strndup")]
 	public string ndup (size_t n);
 
@@ -1167,7 +1168,8 @@ public class string {
 	long utf8_strlen (ssize_t max);
 
 	public long length {
-		get { return this.utf8_strlen (-1); }
+		[CCode (cname = "strlen")]
+		get;
 	}
 
 	public uint8[] data {



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