Changeset 2122
- Timestamp:
- 04/15/08 10:00:43 (1 month ago)
- Files:
-
- libswish3/trunk/src/libswish3/string.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
libswish3/trunk/src/libswish3/string.c
r2116 r2122 509 509 sl->n = 0; 510 510 sl->word = swish_xmalloc(2 * sizeof(xmlChar *)); 511 /* 2 to allow for 512 * NULL-terminate 513 */ 511 /* 2 to allow for NULL-terminate */ 514 512 return sl; 515 513 } … … 525 523 swish_xfree(sl->word); 526 524 swish_xfree(sl); 525 } 526 527 void 528 swish_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 543 swish_StringList * 544 swish_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; 527 557 } 528 558 … … 550 580 551 581 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 */ 554 583 if (!*p) { 555 584 swish_xfree(p);
