Re: glib strlen ?



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'.
Second, it is usually O(n) instead of O(1).

mark

-- 
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/




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