Re: gtk_list_find() problem



On Fri, Dec 31, 2004 at 09:52:45AM -0500, Owen Taylor wrote:
On Fri, 2004-12-31 at 07:16 -0600, David wrote:
 
Hmm.. wait a minute.. A light just came on!  I'm assuming that what's
contained in the GList is a pointer to the string.  So g_list_find()
is actually comparing the value of what's stored in the list to the
pointer value passed by the 'find' function.  I just tried this in my
test program and when I run 'find' using a g_strdup(els[1]), it
_doesn't_ find it, so that must be the case.

g_list_find_custom() with strcmp as the GCompareFunc should do what you
want. (Assuming you want to check for exact byte-for-byte equality.0

Regards,

Yes.  That does the trick.  After sending off my this reply to which you
are referring, I did just that - well, I actually created a function
that simply had the line "return strcmp(...);".  After reading this
message, I tried it by directly calling strcmp() and it worked
perfectly. (Another aspect I overlooked).

It's quite simple, once you see it.  If I'd given it more thought, I
should have seen that there was a good reason for having the
g_string_find_custom() function, but I was concentrating too hard on
trying to match by the contents of g_string.  Actually, this is as
powerful as having a special g_string_find_str(), which I suggested in
my previous message.

Thanks to both of you for your help (on something I should have seen
already).




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