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



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




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