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

Re: how to read a file, line by line, into a GString?



this is cool.  i first learned of glib from your book.  :)   even if glib had
nothing else but GStrings, it would be one of the most useful libraries...

i'd rather first try solutions from the stable version of glib, since other
people will be compiling this besides me.  i'd rather not have "upgrading to
debian sid" a requirement for compiling this thing.

does this mean that with glib 1.2 this can't be done with an intermediate
char *?   not a problem if it can't.  i'll work around it for now.

pete

begin: Havoc Pennington <hp@redhat.com> quote
> 
> Peter Jay Salzman <p@dirac.org> writes:
> > 
> > i'd like to read a file, line by line (discarding newlines) into a GString.
> > 
> > i can't figure out how to do this without using an intermediary char *, which
> > defeats the whole purpose of using GStrings in the first place.
> > 
> > well, i CAN do it using GString foo->str, but of course, i want to use
> > GString's access functions; not trample over its string data...
> > 
> 
> Look at the implementation of g_file_get_contents() in the unstable
> version of GLib. This uses g_string_append_len() though, GLib 1.2
> GString will not handle embedded nul bytes and doesn't have the
> append_len function, so you'll need to modify it slightly.
> 
> Havoc

-- 
"The following addresses had permanent fatal errors..."      p@dirac.org
                               -- Mailer Daemon              www.dirac.org/p




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