From 3eba413ef7e80467c7831731a8e35c733e447c47 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Sun, 18 Mar 2007 12:59:56 +0000 Subject: [PATCH] Added wrbuf_cut_right which cuts WRBUF by a number of characters (chop right). --- include/yaz/wrbuf.h | 15 ++++++++++++++- src/wrbuf.c | 9 ++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/yaz/wrbuf.h b/include/yaz/wrbuf.h index f7eb963..2007567 100644 --- a/include/yaz/wrbuf.h +++ b/include/yaz/wrbuf.h @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: wrbuf.h,v 1.23 2007-01-06 16:05:24 adam Exp $ */ +/* $Id: wrbuf.h,v 1.24 2007-03-18 12:59:56 adam Exp $ */ /** * \file wrbuf.h @@ -39,6 +39,7 @@ YAZ_BEGIN_CDECL +/** \brief string buffer */ typedef struct wrbuf { char *buf; @@ -46,10 +47,19 @@ typedef struct wrbuf int size; } wrbuf, *WRBUF; +/** \brief allocate / construct WRBUF */ YAZ_EXPORT WRBUF wrbuf_alloc(void); + +/** \brief free WRBUF and possibly its buffer */ YAZ_EXPORT void wrbuf_free(WRBUF b, int free_buf); + +/** \brief destroy WRBUF and its buffer */ YAZ_EXPORT void wrbuf_destroy(WRBUF b); + +/** \brief empty WRBUF content */ YAZ_EXPORT void wrbuf_rewind(WRBUF b); + +/** \brief grow WRBUF larger */ 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_xmlputs_n(WRBUF b, const char *cp, int size); @@ -73,6 +83,9 @@ YAZ_EXPORT int wrbuf_iconv_putchar(WRBUF b, yaz_iconv_t cd, int ch); YAZ_EXPORT void wrbuf_chop_right(WRBUF b); +/** \brief cut size of WRBUF */ +YAZ_EXPORT void wrbuf_cut_right(WRBUF b, size_t no_to_remove); + #define wrbuf_len(b) ((b)->pos) #define wrbuf_buf(b) ((b)->buf) diff --git a/src/wrbuf.c b/src/wrbuf.c index e8e6434..973f080 100644 --- a/src/wrbuf.c +++ b/src/wrbuf.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: wrbuf.c,v 1.16 2007-02-23 10:15:01 adam Exp $ + * $Id: wrbuf.c,v 1.17 2007-03-18 12:59:56 adam Exp $ */ /** @@ -231,6 +231,13 @@ const char *wrbuf_cstr(WRBUF b) return b->buf; } +void wrbuf_cut_right(WRBUF b, size_t no_to_remove) +{ + if (no_to_remove > b->pos) + no_to_remove = b->pos; + b->pos = b->pos - no_to_remove; +} + /* * Local variables: * c-basic-offset: 4 -- 1.7.10.4