Re: [Vala] Initializing strings to be used by FileStream::gets
- From: Daniel Thompson <daniel07 redfelineninja org uk>
- To: Jürg Billeter <j bitron ch>
- Cc: vala paldo org
- Subject: Re: [Vala] Initializing strings to be used by FileStream::gets
- Date: Sun, 09 Sep 2007 21:37:05 +0100
On Sun, 2007-09-09 at 20:48 +0200, Jürg Billeter wrote:
I've therefore been trying to figure out how best to grow a string to be
large enough to store the input from fgets. The best I have so far
developed without modifying the bindings is:
var str = "%*d".printf(256, 0);
This at least allows 256 to be a numeric constant somewhere and runs
cleanly with valgrind but it really is pretty grubby.
Have I missed something obvious? If not does anyone have any advice on
how I should improve the bindings?
The string class in Vala should be treated as immutable in most cases,
just like the String classes in C# and Java. I'd recommend you to use
GLib.String (GString in C) if you want a string class that is better
suitable for modification. GLib.String can be compared to the
StringBuilder classes in C# and Java, maybe we should rename the class
in the Vala bindings to reduce some confusion about "string" and
"String".
Something like the following should work:
var str = new String.sized (256);
stdin.gets (str.str, 256);
Thanks. This works as expected.
What do other people think about renaming GLib.String to
GLib.StringBuilder?
I'm only a beginner so can't really having a meaningful opinion renaming
something I've only just discovered.
However if strings are to be treated as immutable is strikes me that a
way of binding fgets() to Glib.String rather than string (or allowing it
return an freshly allocated string) would be an important enhancement to
prevent the breaking of that illusion.
--
Daniel Thompson <daniel07 redfelineninja org uk>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]