]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
posix: Bind va_list and add string.concat() (POSIX)
authorDr. Michael Lauer <mickey@vanille-media.de>
Fri, 16 Mar 2018 14:33:08 +0000 (15:33 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 8 May 2018 06:27:21 +0000 (08:27 +0200)
This fixes string templates when using the POSIX profile.

vapi/posix.vapi

index 916ead5ff8fea980286562c193a812f6b6539674..93eb80b70316b2e3762446a655458ce2069b3a8e 100644 (file)
@@ -251,6 +251,17 @@ public struct time_t {
        public time_t ();
 }
 
+[SimpleType]
+[CCode (cheader_filename = "stdarg.h", cprefix = "va_", has_type_id = false, destroy_function = "va_end", lvalue_access = false)]
+public struct va_list {
+       [CCode (cname = "va_start")]
+       public va_list ();
+       [CCode (cname = "va_copy")]
+       public va_list.copy (va_list src);
+       [CCode (generic_type_pos = 1.1, simple_generics = true)]
+       public unowned G arg<G> ();
+}
+
 [Compact]
 [Immutable]
 [CCode (cname = "char", const_cname = "const char", copy_function = "strdup", free_function = "free", cheader_filename = "stdlib.h,string.h")]
@@ -258,6 +269,20 @@ public class string {
        [PrintfFormat]
        public string printf (...);
 
+       public string concat (...) {
+               string result = this;
+               var l = va_list ();
+               while (true) {
+                       unowned string? arg = l.arg ();
+                       if (arg == null) {
+                               break;
+                       } else {
+                               result += arg;
+                       }
+               }
+               return result;
+       }
+
        public inline unowned string to_string () {
                return this;
        }