From: Adam Dickmeiss Date: Thu, 15 Nov 2007 08:45:52 +0000 (+0000) Subject: Introduce wrbuf_{write,puts}_escaped. X-Git-Tag: YAZ.3.0.18~20 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=0d6e26ddc9a74fb5668efb2a8c72d58a2f4ea770;p=yaz-moved-to-github.git Introduce wrbuf_{write,puts}_escaped. Introduce wrbuf_{write,puts}_escaped. Removed wrbuf_verbose_str which now has the new name wrbuf_write_escaped. wrbuf_verbose_str has not been used outside YAZ in released software so this should be safe. Added a few Doxygen comments for wrbuf.h as well. --- diff --git a/include/yaz/wrbuf.h b/include/yaz/wrbuf.h index 47fd7c7..ef21998 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.27 2007-09-17 19:14:26 adam Exp $ */ +/* $Id: wrbuf.h,v 1.28 2007-11-15 08:45:52 adam Exp $ */ /** * \file wrbuf.h @@ -56,14 +56,26 @@ 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); +/** \brief writes (append) buffer to WRBUF */ 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); +/** \brief appends C-string to WRBUF */ YAZ_EXPORT int wrbuf_puts(WRBUF b, const char *buf); + +/** \brief writes buffer to WRBUF and XML encode (as CDATA) */ +YAZ_EXPORT int wrbuf_xmlputs_n(WRBUF b, const char *cp, int size); +/** \brief writes C-String to WRBUF and XML encode (as CDATA) */ +YAZ_EXPORT int wrbuf_xmlputs(WRBUF b, const char *cp); + YAZ_EXPORT int wrbuf_puts_replace_char(WRBUF b, const char *buf, const char from, const char to); -YAZ_EXPORT int wrbuf_xmlputs(WRBUF b, const char *cp); + +/** \brief writes buffer to WRBUF and escape non-ASCII characters */ +YAZ_EXPORT void wrbuf_puts_escaped(WRBUF b, const char *str); + +/** \brief writes C-string to WRBUF and escape non-ASCII characters */ +YAZ_EXPORT void wrbuf_write_escaped(WRBUF b, const char *buf, size_t len); + +/** \brief writes printf result to WRBUF */ YAZ_EXPORT void wrbuf_printf(WRBUF b, const char *fmt, ...) #ifdef __GNUC__ __attribute__ ((format (printf, 2, 3))) @@ -85,6 +97,12 @@ 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); + +/** \brief grow WRBUF larger + This function is normally not used by applications +*/ +YAZ_EXPORT int wrbuf_grow(WRBUF b, int minsize); + #define wrbuf_len(b) ((b)->pos) #define wrbuf_buf(b) ((b)->buf) @@ -94,9 +112,6 @@ 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 09acce7..ce77914 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.21 2007-10-15 12:00:31 adam Exp $ + * $Id: wrbuf.c,v 1.22 2007-11-15 08:45:52 adam Exp $ */ /** @@ -240,7 +240,12 @@ 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) +void wrbuf_puts_escaped(WRBUF b, const char *str) +{ + return wrbuf_write_escaped(b, str, strlen(str)); +} + +void wrbuf_write_escaped(WRBUF b, const char *str, size_t len) { size_t i; for (i = 0; i < len; i++) diff --git a/util/yaz-icu.c b/util/yaz-icu.c index b7542ad..56e2bf4 100644 --- a/util/yaz-icu.c +++ b/util/yaz-icu.c @@ -2,7 +2,7 @@ * Copyright (C) 1995-2007, Index Data ApS * See the file LICENSE for details. * - * $Id: yaz-icu.c,v 1.14 2007-11-15 08:28:08 adam Exp $ + * $Id: yaz-icu.c,v 1.15 2007-11-15 08:45:52 adam Exp $ */ #if HAVE_CONFIG_H @@ -477,9 +477,11 @@ static void process_text_file(const struct config_t *p_config) else { const char *sortkey = icu_chain_token_sortkey(config.chain); wrbuf_rewind(sw); - wrbuf_verbose_str(sw, sortkey, strlen(sortkey)); + wrbuf_puts_escaped(sw, sortkey); token_count++; if (p_config->xmloutput) + { + /* should XML encode this. Bug #1902 */ fprintf(config.outfile, "\n", @@ -488,6 +490,7 @@ static void process_text_file(const struct config_t *p_config) icu_chain_token_norm(config.chain), icu_chain_token_display(config.chain), wrbuf_cstr(sw)); + } else fprintf(config.outfile, "%lu %lu '%s' '%s' '%s'\n", token_count,