Re: Usage of g_str_strip



On Mon, 2005-10-17 at 14:11 +0530, Sankar P wrote:
Hey all,

There is a function g_strstrip defined to strip-off the leading and
trailing spaces from a string. However, the working of this function is
a bit confusing.

I have the following code-snippet :

name = g_strstrip ( g_strdup (gtk_entry_get_text(GTK_ENTRY
(name_entry))));
g_free (name);

Is this leaking memory?

No.

 I dont understand clearly how g_strstrip works. 
Do I need to store the g_strdup in a pointer and free it instead of the
name?

No, you are freeing the memory allocated in g_strdup. g_strstrip does
not allocate memory.

 The Devhelp doesnt clearly specify anything about it.
Please clarify. 

#define g_strstrip( string )    g_strchomp (g_strchug (string))

Both g_strchung and g_strchomp works with the string you passed to it
and does not allocate memory.

The first moves the text to the start of the buffer with g_memmove and
the second just places a null character in each space character from the
end of the buffer to the first non-space character.

http://cvs.gnome.org/viewcvs/glib/glib/gstrfuncs.c?
rev=1.116.2.2&view=markup
-- 
Iago Rubio




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