YAZ  5.34.0
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 
42 typedef struct wrbuf
43 {
44  char *buf;
45  size_t pos;
46  size_t size;
48 
52 YAZ_EXPORT WRBUF wrbuf_alloc(void);
53 
59 YAZ_EXPORT void wrbuf_destroy(WRBUF b);
60 
64 YAZ_EXPORT void wrbuf_rewind(WRBUF b);
65 
71 YAZ_EXPORT void wrbuf_write(WRBUF b, const char *buf, size_t size);
72 
79 YAZ_EXPORT void wrbuf_insert(WRBUF b, size_t pos, const char *buf, size_t size);
80 
85 YAZ_EXPORT void wrbuf_puts(WRBUF b, const char *buf);
86 
91 YAZ_EXPORT void wrbuf_vp_puts(const char *buf, void *client_data);
92 
98 YAZ_EXPORT void wrbuf_xmlputs_n(WRBUF b, const char *cp, size_t size);
99 
104 YAZ_EXPORT void wrbuf_xmlputs(WRBUF b, const char *cp);
105 
112 YAZ_EXPORT void wrbuf_puts_replace_char(WRBUF b, const char *buf,
113  const char from, const char to);
114 
121 YAZ_EXPORT void wrbuf_puts_replace_str(WRBUF b, const char *buf,
122  const char *from, const char *to);
123 
130 YAZ_EXPORT void wrbuf_puts_escaped(WRBUF b, const char *str);
131 
139 YAZ_EXPORT void wrbuf_write_escaped(WRBUF b, const char *buf, size_t len);
140 
145 YAZ_EXPORT void wrbuf_printf(WRBUF b, const char *fmt, ...)
146 #ifdef __GNUC__
147  __attribute__ ((format (printf, 2, 3)))
148 #endif
149  ;
150 
160 int wrbuf_iconv_write2(WRBUF b, yaz_iconv_t cd, const char *buf,
161  size_t size,
162  void (*wfunc)(WRBUF, const char *, size_t));
163 
175 int wrbuf_iconv_write_x(WRBUF b, yaz_iconv_t cd, const char *buf,
176  size_t size, int cdata)
177 #ifdef __GNUC__
178  __attribute__ ((deprecated))
179 #endif
180  ;
181 
188 YAZ_EXPORT void wrbuf_iconv_write(WRBUF b, yaz_iconv_t cd, const char *buf,
189  size_t size);
190 
197 YAZ_EXPORT void wrbuf_iconv_write_cdata(WRBUF b, yaz_iconv_t cd,
198  const char *buf, size_t size);
199 
205 YAZ_EXPORT void wrbuf_iconv_puts(WRBUF b, yaz_iconv_t cd, const char *str);
206 
212 YAZ_EXPORT void wrbuf_iconv_puts_cdata(WRBUF b, yaz_iconv_t cd,
213  const char *str);
214 
220 YAZ_EXPORT void wrbuf_iconv_putchar(WRBUF b, yaz_iconv_t cd, int ch);
221 
229 YAZ_EXPORT void wrbuf_iconv_reset(WRBUF b, yaz_iconv_t cd);
230 
234 YAZ_EXPORT void wrbuf_chop_right(WRBUF b);
235 
240 YAZ_EXPORT void wrbuf_cut_right(WRBUF b, size_t no_to_remove);
241 
248 YAZ_EXPORT int wrbuf_grow(WRBUF b, size_t minsize);
249 
250 #define wrbuf_len(b) ((b)->pos)
251 #define wrbuf_buf(b) ((b)->buf)
252 
257 YAZ_EXPORT const char *wrbuf_cstr(WRBUF b);
258 
265 YAZ_EXPORT
266 const char *wrbuf_cstr_null(WRBUF b);
267 
268 #define wrbuf_putc(b, c) \
269  ((void) ((b)->pos >= (b)->size ? wrbuf_grow(b, 1) : 0), \
270  (b)->buf[(b)->pos++] = (c))
271 
272 
277 YAZ_EXPORT
278 void wrbuf_json_puts(WRBUF b, const char *str);
279 
285 YAZ_EXPORT
286 void wrbuf_json_write(WRBUF b, const char *cp, size_t sz);
287 
288 YAZ_EXPORT
290  const char *buf, size_t size);
291 
292 YAZ_EXPORT
293 void wrbuf_iconv_json_puts(WRBUF b, yaz_iconv_t cd, const char *strz);
294 
303 YAZ_EXPORT
304 int wrbuf_sha1_write(WRBUF b, const char *cp, size_t sz, int hexit);
305 
313 YAZ_EXPORT
314 int wrbuf_sha1_puts(WRBUF b, const char *cp, int hexit);
315 
317 
318 #endif
319 /*
320  * Local variables:
321  * c-basic-offset: 4
322  * c-file-style: "Stroustrup"
323  * indent-tabs-mode: nil
324  * End:
325  * vim: shiftwidth=4 tabstop=8 expandtab
326  */
327 
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:268
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:240
void wrbuf_json_puts(WRBUF b, const char *str)
writes JSON text to WRBUF with escaping
Definition: wrbuf.c:354
void wrbuf_write_escaped(WRBUF b, const char *buf, size_t len)
writes buffer to WRBUF and escape non-ASCII characters
Definition: wrbuf.c:309
void wrbuf_printf(WRBUF b, const char *fmt,...)
writes printf result to WRBUF
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:190
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
const char * wrbuf_cstr_null(WRBUF b)
returns WRBUF content as C-string or NULL
Definition: wrbuf.c:288
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:230
void wrbuf_puts_escaped(WRBUF b, const char *str)
writes C-string to WRBUF and escape non-ASCII characters
Definition: wrbuf.c:304
void wrbuf_iconv_puts(WRBUF b, yaz_iconv_t cd, const char *str)
iconv converts C-string and appends to WRBUF
Definition: wrbuf.c:235
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:257
struct wrbuf wrbuf
string buffer
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:297
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:223
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
const char * wrbuf_cstr(WRBUF b)
returns WRBUF content as C-string
Definition: wrbuf.c:281
void wrbuf_puts(WRBUF b, const char *buf)
appends C-string to WRBUF
Definition: wrbuf.c:89
void wrbuf_iconv_json_puts(WRBUF b, yaz_iconv_t cd, const char *strz)
Definition: wrbuf.c:263
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:319
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:252
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:247
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