YAZ  4.2.57
Functions
wrbuf.c File Reference

Implements WRBUF (growing buffer) More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <yaz/wrbuf.h>
#include <yaz/snprintf.h>
#include <yaz/yaz-iconv.h>

Go to the source code of this file.

Functions

WRBUF wrbuf_alloc (void)
 construct WRBUF
void wrbuf_destroy (WRBUF b)
 destroy WRBUF and its buffer
void wrbuf_rewind (WRBUF b)
 empty WRBUF content (length of buffer set to 0)
int wrbuf_grow (WRBUF b, size_t minsize)
 grow WRBUF larger
void wrbuf_write (WRBUF b, const char *buf, size_t size)
 append constant size buffer to WRBUF
void wrbuf_insert (WRBUF b, size_t pos, const char *buf, size_t size)
 inserts buffer into WRBUF at some position
void wrbuf_puts (WRBUF b, const char *buf)
 appends C-string to WRBUF
void wrbuf_vp_puts (const char *buf, void *client_data)
 appends C-string to WRBUF - void pointer variant
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
void wrbuf_chop_right (WRBUF b)
 chips traling blanks away from WRBUF
void wrbuf_xmlputs (WRBUF b, const char *cp)
 writes C-String to WRBUF and XML encode (as CDATA)
void wrbuf_xmlputs_n (WRBUF b, const char *cp, size_t size)
 writes buffer of certain size to WRBUF and XML encode (as CDATA)
void wrbuf_printf (WRBUF b, const char *fmt,...)
 writes printf result to WRBUF
int wrbuf_iconv_write_x (WRBUF b, yaz_iconv_t cd, const char *buf, size_t size, int cdata)
 general writer of string using iconv and cdata
void wrbuf_iconv_write (WRBUF b, yaz_iconv_t cd, const char *buf, size_t size)
 iconv converts buffer and appends to WRBUF
void wrbuf_iconv_puts (WRBUF b, yaz_iconv_t cd, const char *strz)
 iconv converts C-string and appends to WRBUF
void wrbuf_iconv_putchar (WRBUF b, yaz_iconv_t cd, int ch)
 iconv converts character and appends to WRBUF
void wrbuf_iconv_write_cdata (WRBUF b, yaz_iconv_t cd, const char *buf, size_t size)
 iconv converts buffer and appends to WRBUF as XML CDATA
void wrbuf_iconv_puts_cdata (WRBUF b, yaz_iconv_t cd, const char *strz)
 iconv converts C-string and appends to WRBUF as XML CDATA
void wrbuf_iconv_reset (WRBUF b, yaz_iconv_t cd)
 iconv reset(flush) to WRBUF
const char * wrbuf_cstr (WRBUF b)
 returns WRBUF content as C-string
void wrbuf_cut_right (WRBUF b, size_t no_to_remove)
 cut size of WRBUF
void wrbuf_puts_escaped (WRBUF b, const char *str)
 writes C-string to WRBUF and escape non-ASCII characters
void wrbuf_write_escaped (WRBUF b, const char *str, size_t len)
 writes buffer to WRBUF and escape non-ASCII characters

Detailed Description

Implements WRBUF (growing buffer)

Definition in file wrbuf.c.

Function Documentation

WRBUF wrbuf_alloc ( void  )
void wrbuf_chop_right ( WRBUF  b)

chips traling blanks away from WRBUF

Parameters
bWRBUF

Definition at line 112 of file wrbuf.c.

References wrbuf::buf, and wrbuf::pos.

Referenced by yaz_rpnquery_to_wrbuf().

const char* wrbuf_cstr ( WRBUF  b)
void wrbuf_cut_right ( WRBUF  b,
size_t  no_to_remove 
)

cut size of WRBUF

Parameters
bWRBUF
no_to_removenumber of bytes to remove

Definition at line 259 of file wrbuf.c.

References wrbuf::pos.

Referenced by yaz_marc_line_gets().

void wrbuf_destroy ( WRBUF  b)
int wrbuf_grow ( WRBUF  b,
size_t  minsize 
)

grow WRBUF larger

Parameters
bWRBUF
minsizemake WRBUF at least this size

This function is normally not used by applications

Definition at line 50 of file wrbuf.c.

References wrbuf::buf, wrbuf::size, xmalloc, and xrealloc.

Referenced by wrbuf_insert(), and wrbuf_write().

void wrbuf_iconv_putchar ( WRBUF  b,
yaz_iconv_t  cd,
int  ch 
)

iconv converts character and appends to WRBUF

Parameters
bWRBUF
cdiconv handle
chcharacter

Definition at line 222 of file wrbuf.c.

References wrbuf_iconv_write().

Referenced by yaz_marc_write_iso2709().

void wrbuf_iconv_puts ( WRBUF  b,
yaz_iconv_t  cd,
const char *  str 
)

iconv converts C-string and appends to WRBUF

Parameters
bWRBUF
cdiconv handle
strC-string

Definition at line 217 of file wrbuf.c.

References wrbuf_iconv_write().

Referenced by add_marc_datafield_turbo_xml(), yaz_marc_write_iso2709(), yaz_marc_write_line(), yaz_marc_write_marcxml_wrbuf(), yaz_marc_write_xml(), and yaz_marc_write_xml_turbo_xml().

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

Parameters
bWRBUF
cdiconv handle
strC-string

Definition at line 234 of file wrbuf.c.

References wrbuf_iconv_write_x().

void wrbuf_iconv_reset ( WRBUF  b,
yaz_iconv_t  cd 
)

iconv reset(flush) to WRBUF

Parameters
b
cdiconv handle

This function calls iconv(cd, 0, 0, ..) to make it flush any remaining content.

Definition at line 239 of file wrbuf.c.

References wrbuf_write(), and yaz_iconv().

Referenced by marc_iconv_reset(), return_string_record(), and yaz_query_charset_convert_buf().

void wrbuf_iconv_write ( WRBUF  b,
yaz_iconv_t  cd,
const char *  buf,
size_t  size 
)

iconv converts buffer and appends to WRBUF

Parameters
bWRBUF
cdiconv handle
bufbuffer
sizesize of buffer

Definition at line 212 of file wrbuf.c.

References wrbuf_iconv_write_x().

Referenced by add_marc_datafield_turbo_xml(), return_string_record(), wrbuf_iconv_putchar(), wrbuf_iconv_puts(), yaz_marc_write_check(), yaz_marc_write_line(), yaz_marc_write_xml(), and yaz_query_charset_convert_buf().

void wrbuf_iconv_write_cdata ( WRBUF  b,
yaz_iconv_t  cd,
const char *  buf,
size_t  size 
)

iconv converts buffer and appends to WRBUF as XML CDATA

Parameters
bWRBUF
cdiconv handle
bufbuffer
sizesize of buffer

Definition at line 229 of file wrbuf.c.

References wrbuf_iconv_write_x().

Referenced by element_name_append_attribute_value(), and yaz_marc_write_marcxml_wrbuf().

int wrbuf_iconv_write_x ( WRBUF  b,
yaz_iconv_t  cd,
const char *  buf,
size_t  size,
int  cdata 
)

general writer of string using iconv and cdata

Parameters
bWRBUF
cdiconv handle (0 for no conversion)
bufbuffer
sizesize of buffer
cdatanon-zero for CDATA; 0 for cdata
Returns
-1 if invalid sequence was encountered (truncation in effect)
0 if buffer could be converted and written

Definition at line 172 of file wrbuf.c.

References wrbuf_write(), wrbuf_xmlputs_n(), yaz_iconv(), YAZ_ICONV_E2BIG, and yaz_iconv_error().

Referenced by opac_element_str(), wrbuf_iconv_puts_cdata(), wrbuf_iconv_write(), and wrbuf_iconv_write_cdata().

void wrbuf_insert ( WRBUF  b,
size_t  pos,
const char *  buf,
size_t  size 
)

inserts buffer into WRBUF at some position

Parameters
bWRBUF
posposition (0=beginning)
bufbuffer
sizesize of buffer

Definition at line 77 of file wrbuf.c.

References wrbuf::buf, wrbuf::pos, wrbuf::size, and wrbuf_grow().

Referenced by yaz_sort_spec_to_type7().

void wrbuf_printf ( WRBUF  b,
const char *  fmt,
  ... 
)
void wrbuf_puts ( WRBUF  b,
const char *  buf 
)
void wrbuf_puts_escaped ( WRBUF  b,
const char *  str 
)

writes C-string to WRBUF and escape non-ASCII characters

Parameters
bWRBUF
strC-string

Non-ASCII characters will be presented as \xDD .

Definition at line 266 of file wrbuf.c.

References wrbuf_write_escaped().

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

Parameters
bWRBUF
bufbuffer to append (C-string)
fromcharacter "from"
tocharcter "to"

Definition at line 99 of file wrbuf.c.

References wrbuf_putc.

Referenced by wr_diag().

void wrbuf_rewind ( WRBUF  b)
void wrbuf_vp_puts ( const char *  buf,
void *  client_data 
)

appends C-string to WRBUF - void pointer variant

Parameters
bufC-string
client_dataassumed WRBUF

Definition at line 93 of file wrbuf.c.

References wrbuf_puts().

Referenced by cql2pqf().

void wrbuf_write ( WRBUF  b,
const char *  buf,
size_t  size 
)
void wrbuf_write_escaped ( WRBUF  b,
const char *  buf,
size_t  len 
)

writes buffer to WRBUF and escape non-ASCII characters

Parameters
bWRBUF
bufbuffer
lensize of buffer

Non-ASCII characters will be presented as \xDD .

Definition at line 271 of file wrbuf.c.

References wrbuf_printf(), and wrbuf_putc.

Referenced by wrbuf_puts_escaped(), and yaz_marc_read_iso2709().

void wrbuf_xmlputs ( WRBUF  b,
const char *  cp 
)

writes C-String to WRBUF and XML encode (as CDATA)

Parameters
bWRBUF
cpCDATA buffer (0-terminated)

Definition at line 120 of file wrbuf.c.

References wrbuf_xmlputs_n().

Referenced by echo_extra_args().

void wrbuf_xmlputs_n ( WRBUF  b,
const char *  cp,
size_t  size 
)

writes buffer of certain size to WRBUF and XML encode (as CDATA)

Parameters
bWRBUF
cpCDATA
sizesize of CDATA

Definition at line 125 of file wrbuf.c.

References wrbuf_putc, and wrbuf_puts().

Referenced by wrbuf_iconv_write_x(), and wrbuf_xmlputs().