Re: Usage of g_str_strip
- From: Sankar P <psankar novell com>
- To: Iago Rubio <iago iagorubio com>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: Usage of g_str_strip
- Date: Mon, 17 Oct 2005 16:57:20 +0530
Thanks a lot.
Your explanation was crisp/clear and probably could be added to devhelp.
Regards,
Sankar P
On Mon, 2005-10-17 at 13:02 +0200, Iago Rubio wrote:
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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]