Re: [Vala] would like to eliminate compilation warning related to stripping whitespace from elements of a string []



2013/6/21 Reid Thompson <Reid Thompson ateb com>


how do I implement the following to make the compilation warnings go
away?

$ cat readMDF.vala
/*valac --pkg gio-2.0 gio-sample.vala*/


int main (string[] args) {
    // A reference to our file
    var file = File.new_for_path (args[1]);

    if (!file.query_exists ()) {
        stderr.printf ("File '%s' doesn't exist.\n", file.get_path ());
        return 1;
    }

    try {
        // Open file for reading and wrap returned FileInputStream into a
        // DataInputStream, so we can read line by line
        var dis = new DataInputStream (file.read ());
        string line;
        // Read lines until end of file (null) is reached
        while ((line = dis.read_line (null)) != null) {
//            stdout.printf ("%s\n", line);
//            foreach(var field in line.split("|")){
//                stdout.printf ("%s\n", field);
//            }



            var fieldAry = line.split("|");
            int i = 0;
            while(i<fieldAry.length){
                stdout.printf ("%6d%60s\n", i, fieldAry[i].strip());
                i++;
            }


//            foreach(string fl in fieldAry) {
//                string as = fl.to_string();
//                stdout.printf ("%60s\n",  as.strip());
//            }



        }
    } catch (Error e) {
        error ("%s", e.message);
    }

    return 0;
}

[16:41:16][0s] rthompso raker2 ateb com> ~
$ valac --pkg gee-1.0 --pkg gio-2.0 readMDF.vala
/home/rthompso/readMDF.vala.c: In function ‘string_strip’:
/home/rthompso/readMDF.vala.c:34:2: warning: passing argument 1 of
‘g_strchug’ discards ‘const’ qualifier from pointer target type [enabled by
default]
/usr/include/glib-2.0/glib/gstrfuncs.h:177:23: note: expected ‘gchar *’
but argument is of type ‘const gchar *’
/home/rthompso/readMDF.vala.c: In function ‘main’:
/home/rthompso/readMDF.vala.c:186:2: warning: ‘g_type_init’ is deprecated
(declared at /usr/include/glib-2.0/gobject/gtype.h:669)
[-Wdeprecated-declarations]

[16:41:22][0s] rthompso raker2 ateb com> ~
$ ./readMDF ./testPipeFile.txt
     0                                          No trimming needed
     1                                          leading whitespace
     2                                         trailing whitespace
     3                        both leading and trailing whitespace
     4

[16:41:26][0s] rthompso raker2 ateb com> ~
$ cat ./testPipeFile.txt
No trimming needed|    leading whitespace|trailing whitespace    |   both
leading and trailing whitespace    |


Hi,

those are long standing bugs in valac itself as far as I know,
and can't be fixed from within the Vala code itself.

Jonas


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