Re: [Vala] What is the right syntax for defining pointers or references or "aliases" in Vala ?



On 06/21/2011 08:00 PM, Jim Nelson wrote:
Actually, string.strip() (which uses g_strstrip) returns a new string.

Yes, string.strip() returns a new string, but string._strip() [note the
underscore] doesn't return anything and just modifies the calling string
in-place. Both of them exist in the string API.

Best regards
        Christian

However, you're right, string is not immutable.  This works:

void main() {
    string a = "abc";
    stdout.printf("%s\n", a);
   
    a.data[0] = 'A';
    stdout.printf("%s\n", a);
}

-- Jim

On Tue, Jun 21, 2011 at 12:27 AM, Christian Siefkes <christian siefkes net
<mailto:christian siefkes net>> wrote:

    On 06/21/2011 01:29 AM, Jonathan Ryan wrote:
    > Also remember that "[t]he data type for strings is string. Vala
    strings are UTF-8 encoded and immutable."
    [http://live.gnome.org/Vala/Tutorial#Strings]
    > If they are to be immutable, assigning strings must yield shallow copies.

    Though they are not *completely* immutable, e.g. calling str._strip() will
    modify a string in place (or so I think).


-- 
|------- Dr. Christian Siefkes ------- christian siefkes net -------
| Homepage: http://www.siefkes.net/ | Blog: http://www.keimform.de/
|    Peer Production Everywhere:       http://peerconomy.org/wiki/
|---------------------------------- OpenPGP Key ID: 0x346452D8 --
Real stupidity beats Artificial Intelligence every time.
        -- Terry Pratchett, Hogfather

Attachment: signature.asc
Description: OpenPGP digital signature



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