YAZ 5.35.1
wrbuf.h
Go to the documentation of this file.
1/* This file is part of the YAZ toolkit.
2 * Copyright (C) Index Data.
3 * All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of Index Data nor the names of its contributors
13 * may be used to endorse or promote products derived from this
14 * software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
33#ifndef WRBUF_H
34#define WRBUF_H
35
36#include <yaz/xmalloc.h>
37#include <yaz/yaz-iconv.h>
38
40
42typedef struct wrbuf
43{
44 char *buf;
45 size_t pos;
46 size_t size;
48
52YAZ_EXPORT WRBUF wrbuf_alloc(void);
53
59YAZ_EXPORT void wrbuf_destroy(WRBUF b);
60
64YAZ_EXPORT void wrbuf_rewind(WRBUF b);
65
71YAZ_EXPORT void wrbuf_write(WRBUF b, const char *buf, size_t size);
72
79YAZ_EXPORT void wrbuf_insert(WRBUF b, size_t pos, const char *buf, size_t size);
80
85YAZ_EXPORT void wrbuf_puts(WRBUF b, const char *buf);
86
91YAZ_EXPORT void wrbuf_vp_puts(const char *buf, void *client_data);
92
98YAZ_EXPORT void wrbuf_xmlputs_n(WRBUF b, const char *cp, size_t size);
99
105YAZ_EXPORT void wrbuf_xml_strip(WRBUF b, const char *cp, size_t size);
106
111YAZ_EXPORT void wrbuf_xmlputs(WRBUF b, const char *cp);
112
119YAZ_EXPORT void wrbuf_puts_replace_char(WRBUF b, const char *buf,
120 const char from, const char to);
121
128YAZ_EXPORT void wrbuf_puts_replace_str(WRBUF b, const char *buf,
129 const char *from, const char *to);
130
137YAZ_EXPORT void wrbuf_puts_escaped(WRBUF b, const char *str);
138
146YAZ_EXPORT void wrbuf_write_escaped(WRBUF b, const char *buf, size_t len);
147
152YAZ_EXPORT void wrbuf_printf(WRBUF b, const char *fmt, ...)
153#ifdef __GNUC__
154 __attribute__ ((format (printf, 2, 3)))
155#endif
156 ;
157
167int wrbuf_iconv_write2(WRBUF b, yaz_iconv_t cd, const char *buf,
168 size_t size,
169 void (*wfunc)(WRBUF, const char *, size_t));
170
179int wrbuf_iconv_puts2(WRBUF b, yaz_iconv_t cd, const char *buf,
180 void (*wfunc)(WRBUF, const char *, size_t));
181
182
194int wrbuf_iconv_write_x(WRBUF b, yaz_iconv_t cd, const char *buf,
195 size_t size, int cdata)
196#ifdef __GNUC__
197 __attribute__ ((deprecated))
198#endif
199 ;
200
207YAZ_EXPORT void wrbuf_iconv_write(WRBUF b, yaz_iconv_t cd, const char *buf,
208 size_t size);
209
216YAZ_EXPORT void wrbuf_iconv_write_cdata(WRBUF b, yaz_iconv_t cd,
217 const char *buf, size_t size);
218
224YAZ_EXPORT void wrbuf_iconv_puts(WRBUF b, yaz_iconv_t cd, const char *str);
225
231YAZ_EXPORT void wrbuf_iconv_puts_cdata(WRBUF b, yaz_iconv_t cd,
232 const char *str);
233
239YAZ_EXPORT void wrbuf_iconv_putchar(WRBUF b, yaz_iconv_t cd, int ch);
240
248YAZ_EXPORT void wrbuf_iconv_reset(WRBUF b, yaz_iconv_t cd);
249
253YAZ_EXPORT void wrbuf_chop_right(WRBUF b);
254
259YAZ_EXPORT void wrbuf_cut_right(WRBUF b, size_t no_to_remove);
260
267YAZ_EXPORT int wrbuf_grow(WRBUF b, size_t minsize);
268
269#define wrbuf_len(b) ((b)->pos)
270#define wrbuf_buf(b) ((b)->buf)
271
276YAZ_EXPORT const char *wrbuf_cstr(WRBUF b);
277
284YAZ_EXPORT
285const char *wrbuf_cstr_null(WRBUF b);
286
287#define wrbuf_putc(b, c) \
288 ((void) ((b)->pos >= (b)->size ? wrbuf_grow(b, 1) : 0), \
289 (b)->buf[(b)->pos++] = (c))
290
291
296YAZ_EXPORT
297void wrbuf_json_puts(WRBUF b, const char *str);
298
304YAZ_EXPORT
305void wrbuf_json_write(WRBUF b, const char *cp, size_t sz);
306
307YAZ_EXPORT
309 const char *buf, size_t size);
310
311YAZ_EXPORT
312void wrbuf_iconv_json_puts(WRBUF b, yaz_iconv_t cd, const char *strz);
313
322YAZ_EXPORT
323int wrbuf_sha1_write(WRBUF b, const char *cp, size_t sz, int hexit);
324
332YAZ_EXPORT
333int wrbuf_sha1_puts(WRBUF b, const char *cp, int hexit);
334
336
337#endif
338/*
339 * Local variables:
340 * c-basic-offset: 4
341 * c-file-style: "Stroustrup"
342 * indent-tabs-mode: nil
343 * End:
344 * vim: shiftwidth=4 tabstop=8 expandtab
345 */
346
string buffer
Definition wrbuf.h:43
size_t size
Definition wrbuf.h:46
size_t pos
Definition wrbuf.h:45
char * buf
Definition wrbuf.h:44
void wrbuf_destroy(WRBUF b)
destroy WRBUF and its buffer
Definition wrbuf.c:38
void wrbuf_insert(WRBUF b, size_t pos, const char *buf, size_t size)
inserts buffer into WRBUF at some position
Definition wrbuf.c:78
void wrbuf_iconv_reset(WRBUF b, yaz_iconv_t cd)
iconv reset(flush) to WRBUF
Definition wrbuf.c:286
const char * wrbuf_cstr(WRBUF b)
returns WRBUF content as C-string
Definition wrbuf.c:299
void wrbuf_rewind(WRBUF b)
empty WRBUF content (length of buffer set to 0)
Definition wrbuf.c:47
WRBUF wrbuf_alloc(void)
construct WRBUF
Definition wrbuf.c:25
void wrbuf_iconv_putchar(WRBUF b, yaz_iconv_t cd, int ch)
iconv converts character and appends to WRBUF
Definition wrbuf.c:258
void wrbuf_json_puts(WRBUF b, const char *str)
writes JSON text to WRBUF with escaping
Definition wrbuf.c:372
void wrbuf_write_escaped(WRBUF b, const char *buf, size_t len)
writes buffer to WRBUF and escape non-ASCII characters
Definition wrbuf.c:327
void wrbuf_printf(WRBUF b, const char *fmt,...)
writes printf result to WRBUF
Definition wrbuf.c:189
void wrbuf_xml_strip(WRBUF b, const char *cp, size_t size)
writes buffer of certain size to WRBUF and strips non-allowed XML chars
Definition wrbuf.c:178
void wrbuf_chop_right(WRBUF b)
chips traling blanks away from WRBUF
Definition wrbuf.c:130
int wrbuf_iconv_write2(WRBUF b, yaz_iconv_t cd, const char *buf, size_t size, void(*wfunc)(WRBUF, const char *, size_t))
General writer of string using iconv and cdata.
Definition wrbuf.c:208
void wrbuf_xmlputs(WRBUF b, const char *cp)
writes C-String to WRBUF and XML encode (as CDATA)
Definition wrbuf.c:138
void wrbuf_puts_replace_str(WRBUF b, const char *buf, const char *from, const char *to)
puts buf to WRBUF and replaces a string with another
Definition wrbuf.c:113
void wrbuf_iconv_write(WRBUF b, yaz_iconv_t cd, const char *buf, size_t size)
Converts buffer using iconv and appends to WRBUF.
Definition wrbuf.c:248
void wrbuf_puts_escaped(WRBUF b, const char *str)
writes C-string to WRBUF and escape non-ASCII characters
Definition wrbuf.c:322
void wrbuf_iconv_puts(WRBUF b, yaz_iconv_t cd, const char *str)
iconv converts C-string and appends to WRBUF
Definition wrbuf.c:253
int wrbuf_sha1_puts(WRBUF b, const char *cp, int hexit)
writes SHA1 text to WRBUF
Definition wrbuf_sha1.c:214
void wrbuf_iconv_json_write(WRBUF b, yaz_iconv_t cd, const char *buf, size_t size)
Definition wrbuf.c:275
int wrbuf_grow(WRBUF b, size_t minsize)
grow WRBUF larger
Definition wrbuf.c:52
void wrbuf_cut_right(WRBUF b, size_t no_to_remove)
cut size of WRBUF
Definition wrbuf.c:315
void wrbuf_puts_replace_char(WRBUF b, const char *buf, const char from, const char to)
puts buf to WRBUF and replaces a single char
Definition wrbuf.c:100
int wrbuf_iconv_write_x(WRBUF b, yaz_iconv_t cd, const char *buf, size_t size, int cdata)
writer of string using iconv and cdata
Definition wrbuf.c:241
void wrbuf_vp_puts(const char *buf, void *client_data)
appends C-string to WRBUF - void pointer variant
Definition wrbuf.c:94
void wrbuf_xmlputs_n(WRBUF b, const char *cp, size_t size)
writes buffer of certain size to WRBUF and XML encode (as CDATA)
Definition wrbuf.c:143
void wrbuf_puts(WRBUF b, const char *buf)
appends C-string to WRBUF
Definition wrbuf.c:89
int wrbuf_iconv_puts2(WRBUF b, yaz_iconv_t cd, const char *buf, void(*wfunc)(WRBUF, const char *, size_t))
General writer of string using iconv and cdata.
Definition wrbuf.c:202
void wrbuf_iconv_json_puts(WRBUF b, yaz_iconv_t cd, const char *strz)
Definition wrbuf.c:281
void wrbuf_write(WRBUF b, const char *buf, size_t size)
append constant size buffer to WRBUF
Definition wrbuf.c:68
void wrbuf_json_write(WRBUF b, const char *cp, size_t sz)
writes JSON text to WRBUF with escaping
Definition wrbuf.c:337
const char * wrbuf_cstr_null(WRBUF b)
returns WRBUF content as C-string or NULL
Definition wrbuf.c:306
void wrbuf_iconv_puts_cdata(WRBUF b, yaz_iconv_t cd, const char *str)
iconv converts C-string and appends to WRBUF as XML CDATA
Definition wrbuf.c:270
struct wrbuf * WRBUF
int wrbuf_sha1_write(WRBUF b, const char *cp, size_t sz, int hexit)
writes SHA1 text to WRBUF
Definition wrbuf_sha1.c:194
void wrbuf_iconv_write_cdata(WRBUF b, yaz_iconv_t cd, const char *buf, size_t size)
Converts buffer using iconv and appends to WRBUF as XML CDATA.
Definition wrbuf.c:265
Header for memory handling functions.
Header for YAZ iconv interface.
#define YAZ_BEGIN_CDECL
Definition yconfig.h:56
#define YAZ_END_CDECL
Definition yconfig.h:57