[Vala] Help: unowned string returns garbage characters



Hello, 

I am refactoring some of my test code into a class and have run
into a problem with unowned strings.

I have a class that has several methods that return strings. These
methods get their value form the response buffer of a Soup Message.

        public string send_misc_method (MiscMethod mm) {
               [...]
               debug ("send_misc_method: %s",
                     (string) message.response_body.flatten ().data); // OK
               return  (string) message.response_body.flatten ().data
        }

        public unowned string get_motd () {
               string s = send_misc_method (MiscMethod.MOTD);
               debug ("get_motd: %s", s);                       // OK
               return s.to_string (); // transfers ownership?
        }

        main (string[] args) {
             [...]
             debug ("main - get_motd: %s", server.get_motd ()); // !OK
             // var s = server.get_motd ();
             // debug ("main - get_motd: %s", s); // also !OK             
        }

output:
** (process:28697): DEBUG: couchdb-server-api.vala:90: 
send_misc_method: {"couchdb":"Welcome","version":"1.2.0a-"}

** (process:28697): DEBUG: couchdb-server-api.vala:104: 
get_motd: {"couchdb":"Welcome","version":"1.2.0a-"}

** (process:28697): DEBUG: couchdb-server-api.vala:146: 
main - get_motd : \xc0\xa0\u0004uchdb":"Welcome","version":"1.2.0a-"}

So, what have I done wrong?

Thank you.

-- 
Regards,
Brian Winfrey




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