From: Adam Dickmeiss Date: Mon, 14 Jul 2003 12:58:18 +0000 (+0000) Subject: New utility wrbuf_xmlputs X-Git-Tag: YAZ.2.0.4~26 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=9360e7e7d56e77fb1253faa1232c0417cd5d3ee3;p=yaz-moved-to-github.git New utility wrbuf_xmlputs --- diff --git a/include/yaz/wrbuf.h b/include/yaz/wrbuf.h index 3b6258d..58c2460 100644 --- a/include/yaz/wrbuf.h +++ b/include/yaz/wrbuf.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: wrbuf.h,v 1.8 2003-01-06 08:20:27 adam Exp $ + * $Id: wrbuf.h,v 1.9 2003-07-14 12:58:18 adam Exp $ * */ @@ -47,6 +47,7 @@ YAZ_EXPORT void wrbuf_rewind(WRBUF b); YAZ_EXPORT int wrbuf_grow(WRBUF b, int minsize); YAZ_EXPORT int wrbuf_write(WRBUF b, const char *buf, int size); YAZ_EXPORT int wrbuf_puts(WRBUF b, const char *buf); +YAZ_EXPORT int wrbuf_xmlputs(WRBUF b, const char *cp); YAZ_EXPORT void wrbuf_printf(WRBUF b, const char *fmt, ...); #define wrbuf_len(b) ((b)->pos) diff --git a/util/wrbuf.c b/util/wrbuf.c index 338ce09..a649e64 100644 --- a/util/wrbuf.c +++ b/util/wrbuf.c @@ -1,9 +1,8 @@ /* * Copyright (c) 1995-2003, Index Data. * See the file LICENSE for details. - * Sebastian Hammer, Adam Dickmeiss * - * $Id: wrbuf.c,v 1.12 2003-01-06 08:20:28 adam Exp $ + * $Id: wrbuf.c,v 1.13 2003-07-14 12:58:18 adam Exp $ */ /* @@ -80,6 +79,37 @@ int wrbuf_puts(WRBUF b, const char *buf) return 0; } +int wrbuf_xmlputs(WRBUF b, const char *cp) +{ + while (*cp) + { + switch(*cp) + { + case '<': + wrbuf_puts(b, "<"); + break; + case '>': + wrbuf_puts(b, ">"); + break; + case '&': + wrbuf_puts(b, "&"); + break; + case '"': + wrbuf_puts(b, """); + break; + case '\'': + wrbuf_puts(b, "'"); + break; + default: + wrbuf_putc(b, *cp); + } + cp++; + } + wrbuf_putc(b, 0); + (b->pos)--; + return 0; +} + void wrbuf_printf(WRBUF b, const char *fmt, ...) { va_list ap;