]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
glib-2.0: add string.get_prev_char()
authorSébastien Wilmet <swilmet@src.gnome.org>
Wed, 4 Jul 2012 19:39:01 +0000 (21:39 +0200)
committerJürg Billeter <j@bitron.ch>
Wed, 18 Jul 2012 09:45:55 +0000 (11:45 +0200)
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.

vapi/glib-2.0.vapi

index 0105881a70952ccf525849b696bb4137677ce5a0..94059639b6a329faafd1ec2dc99449d140ed799a 100644 (file)
@@ -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 ();