Fast, efficient, limitless strings. In C.

From: Forrest J. Cavalier III (mibsoftat_private)
Date: Tue Jul 21 1998 - 03:48:34 PDT

  • Next message: Dale.Babiy: "Re: On compilers and bounds checking (was: EMERGENCY: new remote"

    I have an allocated string library which I'll work
    on documenting and putting on a WWW page.
    
    It implements 4 key string allocation functions, and
    allows you to use the existing "standard" libc and
    other null-terminated string operations we all know
    (and love.)  (I figured, what's the point of a string
    library, if you have to re-implement strchr, strstr,
    strspn, etc.)
    
       char *astrcpy(char **pasz,const char *src);
            /* mallocs or reallocs a buffer. */
       char *astrn0cpy(char **pasz,const char *src,size_t len);
            /* Always stores a '\0' */
       char *astrcat(char **pasz,const char *src);
       char *astrn0cat(char **pasz,const char *src,size_t len);
    
       void astrfree(char **pasz); /* or call free(pasz) */
    
    There is some string tracking and "overallocation" to
    improve efficiency.  In typical use, there is very
    little string moving.
    
    An added bonus: a "limitless" sprintf and fgets are
    also included.
    
    Retrofitting old code is almost as easy as writing new
    code, which would look like this....
       char *pasz = 0;
    
       astrcpy(&pasz,getenv("SOME_BIG_STRING"));
    
       if (strstr(pasz,"bad_path")) {
           .....
       }
    
    
    Licensing is BSD-style. (Free of charge for commercial
    and non-commercial use.)
    
    Header file documentation is decent right now, but I'd
    like to document things a bit better.  It is ready
    for beta testing, grab astring.h (5K) and astring.c
    (27K) from
    
       http://www.mibsoftware.com/libmib/astring/
    
    Please send comments and bug reports to me.
    
    Forrest J. Cavalier III
    Mib Software
    



    This archive was generated by hypermail 2b30 : Fri Apr 13 2001 - 14:06:53 PDT