projects
/
yaz-moved-to-github.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
yaz-iconv: fix typos
[yaz-moved-to-github.git]
/
src
/
wrbuf.c
diff --git
a/src/wrbuf.c
b/src/wrbuf.c
index
871028d
..
6d9b145
100644
(file)
--- a/
src/wrbuf.c
+++ b/
src/wrbuf.c
@@
-1,5
+1,5
@@
/* This file is part of the YAZ toolkit.
/* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2013 Index Data
+ * Copyright (C) Index Data
* See the file LICENSE for details.
*/
* See the file LICENSE for details.
*/
@@
-16,6
+16,7
@@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
+#include <assert.h>
#include <yaz/wrbuf.h>
#include <yaz/snprintf.h>
#include <yaz/wrbuf.h>
#include <yaz/snprintf.h>
@@
-30,6
+31,7
@@
WRBUF wrbuf_alloc(void)
n->buf = 0;
n->size = 0;
n->pos = 0;
n->buf = 0;
n->size = 0;
n->pos = 0;
+ wrbuf_grow(n, 1);
return n;
}
return n;
}
@@
-57,9
+59,8
@@
int wrbuf_grow(WRBUF b, size_t minsize)
togrow = b->size;
if (togrow < minsize)
togrow = minsize;
togrow = b->size;
if (togrow < minsize)
togrow = minsize;
- if (b->size && !(b->buf =(char *)xrealloc(b->buf, b->size += togrow)))
- abort();
- else if (!b->size && !(b->buf = (char *)xmalloc(b->size = togrow)))
+ b->buf = (char *) xrealloc(b->buf, 1 + (b->size += togrow));
+ if (!b->buf)
abort();
return 0;
}
abort();
return 0;
}
@@
-169,8
+170,9
@@
void wrbuf_printf(WRBUF b, const char *fmt, ...)
va_end(ap);
}
va_end(ap);
}
-int wrbuf_iconv_write_x(WRBUF b, yaz_iconv_t cd, const char *buf,
- size_t size, int cdata)
+int wrbuf_iconv_write2(WRBUF b, yaz_iconv_t cd, const char *buf,
+ size_t size,
+ void (*wfunc)(WRBUF, const char *, size_t))
{
int ret = 0;
if (cd)
{
int ret = 0;
if (cd)
@@
-193,40
+195,24
@@
int wrbuf_iconv_write_x(WRBUF b, yaz_iconv_t cd, const char *buf,
break;
}
}
break;
}
}
- switch (cdata)
- {
- case 0:
- wrbuf_write(b, outbuf, outp - outbuf);
- break;
- case 1:
- wrbuf_xmlputs_n(b, outbuf, outp - outbuf);
- break;
- case 2:
- wrbuf_json_write(b, outbuf, outp - outbuf);
- break;
- }
+ (*wfunc)(b, outbuf, outp - outbuf);
}
}
else
}
}
else
- {
- switch (cdata)
- {
- case 0:
- wrbuf_write(b, buf, size);
- break;
- case 1:
- wrbuf_xmlputs_n(b, buf, size);
- break;
- case 2:
- wrbuf_json_write(b, buf, size);
- }
- }
+ (*wfunc)(b, buf, size);
return ret;
}
return ret;
}
+int wrbuf_iconv_write_x(WRBUF b, yaz_iconv_t cd, const char *buf,
+ size_t size, int cdata)
+{
+ return wrbuf_iconv_write2(b, cd, buf, size,
+ cdata ? wrbuf_xmlputs_n : wrbuf_write);
+}
+
void wrbuf_iconv_write(WRBUF b, yaz_iconv_t cd, const char *buf, size_t size)
{
void wrbuf_iconv_write(WRBUF b, yaz_iconv_t cd, const char *buf, size_t size)
{
- wrbuf_iconv_write_x(b, cd, buf, size, 0);
+ wrbuf_iconv_write2(b, cd, buf, size, wrbuf_write);
}
void wrbuf_iconv_puts(WRBUF b, yaz_iconv_t cd, const char *strz)
}
void wrbuf_iconv_puts(WRBUF b, yaz_iconv_t cd, const char *strz)
@@
-243,23
+229,23
@@
void wrbuf_iconv_putchar(WRBUF b, yaz_iconv_t cd, int ch)
void wrbuf_iconv_write_cdata(WRBUF b, yaz_iconv_t cd, const char *buf, size_t size)
{
void wrbuf_iconv_write_cdata(WRBUF b, yaz_iconv_t cd, const char *buf, size_t size)
{
- wrbuf_iconv_write_x(b, cd, buf, size, 1);
+ wrbuf_iconv_write2(b, cd, buf, size, wrbuf_xmlputs_n);
}
void wrbuf_iconv_puts_cdata(WRBUF b, yaz_iconv_t cd, const char *strz)
{
}
void wrbuf_iconv_puts_cdata(WRBUF b, yaz_iconv_t cd, const char *strz)
{
- wrbuf_iconv_write_x(b, cd, strz, strlen(strz), 1);
+ wrbuf_iconv_write2(b, cd, strz, strlen(strz), wrbuf_xmlputs_n);
}
void wrbuf_iconv_json_write(WRBUF b, yaz_iconv_t cd,
const char *buf, size_t size)
{
}
void wrbuf_iconv_json_write(WRBUF b, yaz_iconv_t cd,
const char *buf, size_t size)
{
- wrbuf_iconv_write_x(b, cd, buf, size, 2);
+ wrbuf_iconv_write2(b, cd, buf, size, wrbuf_json_write);
}
void wrbuf_iconv_json_puts(WRBUF b, yaz_iconv_t cd, const char *strz)
{
}
void wrbuf_iconv_json_puts(WRBUF b, yaz_iconv_t cd, const char *strz)
{
- wrbuf_iconv_write_x(b, cd, strz, strlen(strz), 2);
+ wrbuf_iconv_write2(b, cd, strz, strlen(strz), wrbuf_json_write);
}
void wrbuf_iconv_reset(WRBUF b, yaz_iconv_t cd)
}
void wrbuf_iconv_reset(WRBUF b, yaz_iconv_t cd)
@@
-277,8
+263,17
@@
void wrbuf_iconv_reset(WRBUF b, yaz_iconv_t cd)
const char *wrbuf_cstr(WRBUF b)
{
const char *wrbuf_cstr(WRBUF b)
{
- wrbuf_putc(b, '\0'); /* add '\0' */
- (b->pos)--; /* don't include '\0' in count */
+ assert(b && b->pos <= b->size);
+ b->buf[b->pos] = '\0';
+ return b->buf;
+}
+
+const char *wrbuf_cstr_null(WRBUF b)
+{
+ if (!b || b->pos == 0)
+ return 0;
+ assert(b->pos <= b->size);
+ b->buf[b->pos] = '\0';
return b->buf;
}
return b->buf;
}