From: Sébastien Wilmet Date: Wed, 4 Jul 2012 19:39:01 +0000 (+0200) Subject: glib-2.0: add string.get_prev_char() X-Git-Tag: 0.17.4~44 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b4e884c150100d56636d5cf6be4e5311d62bb718;p=thirdparty%2Fvala.git glib-2.0: add string.get_prev_char() This is the opposite of string.get_next_char(). There is a difference though, to be more convenient in a loop: get_next_char() returns the current chararcter, and the next index. get_prev_char() returns the previous character, and the previous index. Fixes bug 655185. --- diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi index 0105881a7..94059639b 100644 --- a/vapi/glib-2.0.vapi +++ b/vapi/glib-2.0.vapi @@ -1005,6 +1005,19 @@ public class string { [CCode (cname = "g_utf8_prev_char")] public unowned string prev_char (); + [CCode (cname = "g_utf8_prev_char")] + static char* utf8_prev_char (char* str); + public bool get_prev_char (ref int index, out unichar c) { + if (0 < index) { + index = (int) (utf8_prev_char ((char*) this + index) - (char*) this); + c = utf8_get_char ((char*) this + index); + return true; + } else { + c = 0; + return false; + } + } + [Deprecated (replacement = "string.length")] [CCode (cname = "strlen")] public long len ();