Changeset 2122

Show
Ignore:
Timestamp:
04/15/08 10:00:43 (1 month ago)
Author:
karpet
Message:

add stringlist utility functions; still TODO is to make StringList? utf-8 safe

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • libswish3/trunk/src/libswish3/string.c

    r2116 r2122  
    509509    sl->n = 0; 
    510510    sl->word = swish_xmalloc(2 * sizeof(xmlChar *)); 
    511 /* 2 to allow for 
    512      * NULL-terminate 
    513 */ 
     511/* 2 to allow for NULL-terminate */ 
    514512    return sl; 
    515513} 
     
    525523    swish_xfree(sl->word); 
    526524    swish_xfree(sl); 
     525} 
     526 
     527void 
     528swish_merge_stringlists( 
     529    swish_StringList *sl1, 
     530    swish_StringList *sl2 
     531) 
     532{ 
     533    int i; 
     534    // add sl1 -> sl2 
     535    sl2->word = (xmlChar **)swish_xrealloc(sl2->word, (sl1->n + sl2->n) * sizeof(xmlChar *) + 1); 
     536    for(i=0; i<sl1->n; i++) { 
     537        // copy is a little overhead, but keeps mem count simple 
     538        sl2->word[sl2->n++] = swish_xstrdup( sl1->word[i] ); 
     539    } 
     540    swish_free_stringlist(sl1); 
     541} 
     542 
     543swish_StringList * 
     544swish_copy_stringlist( 
     545    swish_StringList *sl 
     546) 
     547{ 
     548    swish_StringList *s2; 
     549    int i; 
     550    s2 = swish_init_stringlist(); 
     551    s2->word = (xmlChar **)swish_xrealloc(s2->word, sl->n * sizeof(xmlChar *) + 1); 
     552    for(i=0; i<sl->n; i++) { 
     553        s2->word[i] = swish_xstrdup( sl->word[i] ); 
     554    } 
     555    s2->n = sl->n; 
     556    return s2; 
    527557} 
    528558 
     
    550580 
    551581    while (&line && (p = getword(&line))) { 
    552 /* getword returns "" when not null, so need to free it if we are not 
    553          * using it */ 
     582/* getword returns "" when not null, so need to free it if we are not using it */ 
    554583        if (!*p) { 
    555584            swish_xfree(p);