X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fwrbuf.c;h=fb5968b08cc4594619171edba8281c53f9545609;hb=4f8ea8cfaf2f3d95e4efcf9494526c2b4be43eb8;hp=19c2ce2b8d29ca4660b3bac1f30e6fc846b3d20d;hpb=323dd612ee1939e8082fa75edcd1083a238d5272;p=yaz-moved-to-github.git diff --git a/src/wrbuf.c b/src/wrbuf.c index 19c2ce2..fb5968b 100644 --- a/src/wrbuf.c +++ b/src/wrbuf.c @@ -1,8 +1,8 @@ /* - * Copyright (C) 1995-2005, Index Data ApS + * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: wrbuf.c,v 1.9 2005-09-27 17:52:46 adam Exp $ + * $Id: wrbuf.c,v 1.15 2007-01-06 16:05:24 adam Exp $ */ /** @@ -41,6 +41,11 @@ void wrbuf_free(WRBUF b, int free_buf) xfree(b); } +void wrbuf_destroy(WRBUF b) +{ + wrbuf_free(b, 1); +} + void wrbuf_rewind(WRBUF b) { b->pos = 0; @@ -81,6 +86,21 @@ int wrbuf_puts(WRBUF b, const char *buf) return 0; } +int wrbuf_puts_replace_char(WRBUF b, const char *buf, + const char from, const char to) +{ + while(*buf){ + if (*buf == from) + wrbuf_putc(b, to); + else + wrbuf_putc(b, *buf); + buf++; + } + wrbuf_putc(b, 0); + (b->pos)--; /* don't include '\0' in count */ + return 0; +} + void wrbuf_chop_right(WRBUF b) { while (b->pos && b->buf[b->pos-1] == ' ') @@ -195,11 +215,30 @@ int wrbuf_iconv_write(WRBUF b, yaz_iconv_t cd, const char *buf, int size) return wrbuf_iconv_write_x(b, cd, buf, size, 0); } +int wrbuf_iconv_puts(WRBUF b, yaz_iconv_t cd, const char *strz) +{ + return wrbuf_iconv_write(b, cd, strz, strlen(strz)); +} + +int wrbuf_iconv_putchar(WRBUF b, yaz_iconv_t cd, int ch) +{ + char buf[1]; + buf[0] = ch; + return wrbuf_iconv_write(b, cd, buf, 1); +} + int wrbuf_iconv_write_cdata(WRBUF b, yaz_iconv_t cd, const char *buf, int size) { return wrbuf_iconv_write_x(b, cd, buf, size, 1); } +const char *wrbuf_cstr(WRBUF b) +{ + wrbuf_write(b, "", 1); /* '\0'-terminate as well */ + (b->pos)--; /* don't include '\0' in count */ + return b->buf; +} + /* * Local variables: * c-basic-offset: 4