From 270160339305b73c0b5cdf74f004c684e83e2cd8 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 17 Sep 2007 19:14:26 +0000 Subject: [PATCH] Added wrbuf_verbose_str. --- include/yaz/wrbuf.h | 5 ++++- src/wrbuf.c | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/yaz/wrbuf.h b/include/yaz/wrbuf.h index 56a4023..47fd7c7 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.26 2007-03-20 21:37:31 adam Exp $ */ +/* $Id: wrbuf.h,v 1.27 2007-09-17 19:14:26 adam Exp $ */ /** * \file wrbuf.h @@ -94,6 +94,9 @@ YAZ_EXPORT const char *wrbuf_cstr(WRBUF b); (((b)->pos >= (b)->size ? wrbuf_grow(b, 1) : 0), \ (b)->buf[(b)->pos++] = (c), 0) +/** \brief put readable string in WRBUF from raw input */ +YAZ_EXPORT void wrbuf_verbose_str(WRBUF b, const char *str, size_t len); + YAZ_END_CDECL #endif diff --git a/src/wrbuf.c b/src/wrbuf.c index f90764a..d8a709e 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.19 2007-03-20 21:37:32 adam Exp $ + * $Id: wrbuf.c,v 1.20 2007-09-17 19:14:26 adam Exp $ */ /** @@ -240,6 +240,16 @@ void wrbuf_cut_right(WRBUF b, size_t no_to_remove) b->pos = b->pos - no_to_remove; } +void wrbuf_verbose_str(WRBUF b, const char *str, size_t len) +{ + size_t i; + for (i = 0; i < len; i++) + if (str[i] < ' ' || str[i] > 126) + wrbuf_printf(b, "\\x%02X", str[i] & 0xff); + else + wrbuf_putc(b, str[i]); +} + /* * Local variables: * c-basic-offset: 4 -- 1.7.10.4