[Vala] questions about vapi.



1) patch to add g_utf8_strncpy to glib-2.0.vapi

2) function to replace string.ndup() - utf8_ndup.vala


Questions:

1) I want add g_utf8_strncpy to class string, but these function have no
standart order for their parameters.

gchar*              g_utf8_strncpy   (gchar *dest,
                                     const gchar *src,
                                     gsize n);

I'm try attribute instance_pos, but these attribute have only two value - 0 and
-1 and both values not suitable for these case.

instance_pos=0 place source string on 1'st. But I want reverse order for source
and dest strings.

for example:
dest = source.utf8_ndup(dtring dest, long n)

unstance_pos=-1 will place instance to last position, but in this position must
be long N...


Any ideas?

2) In diffrent this g_strndup, g_utf8_strncpy not automatic create result
buffer

utf8_ndup = g_utf8_strncpy(g_strdup(source),source,n);


Can I  translate function "string.utf8_ndup" to  these C code in vapi file
glib-2.0?

Or vala  can map One vala function to  One C-function only?

--- /home/avl/RPM/tmp/vala-0.3.5/vapi/glib-2.0.vapi     2008-08-10 17:31:12.000000000 +0400
+++ glib-2.0.vapi       2008-08-16 17:56:00.000000000 +0400
@@ -675,6 +675,13 @@
        HANGUL_LVT_SYLLABLE
 }
 
+
+
+namespace String {
+[CCode (cname = "g_utf8_strncpy")]
+public weak string utf8_strncpy (string dest, string src, ulong n);
+}
+
 [Compact]
 [Immutable]
 [CCode (cname = "char", const_cname = "const char", copy_function = "g_strdup", free_function = "g_free", 
cheader_filename = "stdlib.h,string.h,glib.h", type_id = "G_TYPE_STRING", marshaller_type_name = "STRING", 
get_value_function = "g_value_get_string", set_value_function = "g_value_set_string", type_signature = "s")]
@@ -693,6 +700,7 @@
        public string concat (string string2, ...);
        [CCode (cname = "g_strndup")]
        public string ndup (ulong n); /* FIXME: only UTF-8 */
+       
        [CCode (cname = "g_strescape")]
        public string escape (string exceptions);
        [CCode (cname = "g_strcompress")]
//valac -o string  string.vala


//tested function - utf8 replacement for string.ndup()

public static string utf8_ndup (string source, long count) 
    { 
        string retval = source;
        return String.utf8_strncpy(retval,source,count);
    }



public class StringBug : GLib.Object 
 {



    public static int main (string[] args) {

    string  source="тестовая строка ";
    string  result=source;

    long count = source.len()-1;

    //you may set number characters to copy in command line.
    if ( args.length > 1)
        count = args[1].to_long();


    stdout.printf("Source:'%s',Count: %ld,  Result: '%s'\n",source,count,utf8_ndup(source,count));
    return 0;
  }

}


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