Re: glib strlen ?



Hi folks,

First, thank you for all infos.
It's confirmed that no function in glib for strlen, right ? Both gchar and GString.
Why . May be it's related to i18n, multy-byte characters, etc

I use the strlen, and it's ok for this time.
Is it ok  to access the GString's len member directly ?

regards,
mige

Tristan Van Berkom wrote:

Mark Mielke wrote:
On Tue, Mar 25, 2003 at 10:42:18AM -0000, martyn 2 russell bt com wrote:
GLIB is not a replacement for standard string functions, it is more like an
extension.  strlen is perfectly capable of returning the length of a string
you provide it, there is no need to glib to have such a function.
Actually, if he is speaking about a GString object, the following snippet
does what he wants:

   if (string != 0 && string->len != 0)
       /* String is defined and has >0 length... */
   else
       /* String is not defined, or has 0 length... */

strlen(mystr) should be part of string.h
strlen() is defficient in a number of ways. First, it cannot store '\0'.

KISS (Keep It Simple Stupid), whats the point of initializing all kinds of
fancy structures and objects just to manipulate strings ?
string.h is something you can trust; it's _always_ worked.


// here is a string containing a '\0'
char *string = "\0";
// strlen will return 0 length.

// here is something naive
char *string = '\0'
// strlen will never return and you'll
// recieve SIGSEGV for trying to
// reference ('\0'[0])
Second, it is usually O(n) instead of O(1).
huh ? what exactly do you mean ?



Cheers,
        -Tristan


--
mark mielke cc/markm ncf ca/markm nortelnetworks com __________________________
.  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Neighbourhood Coder
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   |
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, Ontario, Canada

 One ring to rule them all, one ring to find them, one ring to bring them all
                      and in the darkness bind them...

                          http://mark.mielke.cc/

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list






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