1 /* $Id: buff.c 3483 2007-05-07 11:18:56Z mquinson $ */
3 /* strbuff -- string buffers */
5 /* Copyright (c) 2007 Martin Quinson. */
6 /* All rights reserved. */
8 /* This program is free software; you can redistribute it and/or modify it
9 * under the terms of the license (GNU LGPL) which comes with this package. */
11 /* specific to Borland Compiler */
16 #include "xbt/strbuff.h"
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(strbuff,xbt,"String buffers");
24 void xbt_strbuff_empty(xbt_strbuff_t b) {
29 xbt_strbuff_t xbt_strbuff_new(void) {
30 xbt_strbuff_t res=malloc(sizeof(s_xbt_strbuff_t));
31 res->data=malloc(512);
33 xbt_strbuff_empty(res);
36 void xbt_strbuff_free(xbt_strbuff_t b) {
43 void xbt_strbuff_append(xbt_strbuff_t b, const char *toadd) {
48 THROW0(arg_error,0,"Asked to append stuff to NULL buffer");
50 addlen = strlen(toadd);
51 needed_space=b->used+addlen+1;
53 if (needed_space > b->size) {
54 b->data = realloc(b->data, needed_space);
55 b->size = needed_space;
57 strcpy(b->data+b->used, toadd);
60 void xbt_strbuff_chomp(xbt_strbuff_t b) {
61 while (b->data[b->used] == '\n') {
62 b->data[b->used] = '\0';
68 void xbt_strbuff_trim(xbt_strbuff_t b) {
69 xbt_str_trim(b->data," ");
70 b->used = strlen(b->data);