| 472 | } |
| 473 | memcpy(sb->buffer + sb->length, str, len + 1); |
| 474 | sb->length += len; |
| 475 | } |
| 476 | |
| 477 | char* StringBuilder_get_buffer(StringBuilder* sb) { |
| 478 | return sb->buffer; |
| 479 | } |
| 480 | |
| 481 | // StringVector utilities |
| 482 | void StringVector_init(StringVector* sv, size_t initial_capacity) { |
| 483 | sv->data = NULL; |
| 484 | sv->count = 0; |
| 485 | sv->capacity = initial_capacity > 0 ? initial_capacity : 8; |
| 486 | if (sv->capacity > 0) { |
| 487 | sv->data = (char**)malloc(sizeof(char*) * sv->capacity); |
| 488 | if (!sv->data) sv->capacity = 0; |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | void StringVector_destroy(StringVector* sv) { |
| 493 | if (sv->data) { |
| 494 | for (size_t i = 0; i < sv->count; ++i) { |
| 495 | if (sv->data[i]) free(sv->data[i]); |
| 496 | } |
no test coverage detected