1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2013 Index Data
3 * See the file LICENSE for details.
8 * \brief Implements NMEM dup utilities
16 #include <yaz/nmem_xml.h>
18 char *nmem_strdup(NMEM mem, const char *src)
20 char *dst = (char *) nmem_malloc(mem, strlen(src)+1);
25 char *nmem_strdup_null(NMEM mem, const char *src)
30 return nmem_strdup(mem, src);
33 char *nmem_strdupn(NMEM mem, const char *src, size_t n)
35 char *dst = (char *) nmem_malloc(mem, n+1);
41 nmem_int_t *nmem_intdup(NMEM mem, nmem_int_t v)
43 nmem_int_t *dst = (nmem_int_t*) nmem_malloc(mem, sizeof(*dst));
48 nmem_bool_t *nmem_booldup(NMEM mem, nmem_bool_t v)
50 nmem_bool_t *dst = (nmem_bool_t*) nmem_malloc(mem, sizeof(*dst));
55 void nmem_strsplit_blank(NMEM nmem, const char *dstr, char ***darray, int *num)
57 nmem_strsplit(nmem, " ", dstr, darray, num);
61 void nmem_strsplit(NMEM nmem, const char *delim, const char *dstr,
62 char ***darray, int *num)
64 nmem_strsplitx(nmem, delim, dstr, darray, num, 1);
67 void nmem_strsplitx(NMEM nmem, const char *delim, const char *dstr,
68 char ***darray, int *num, int collapse)
70 nmem_strsplit_escape(nmem, delim, dstr, darray, num, collapse, 0);
73 void nmem_strsplit_escape(NMEM nmem, const char *delim, const char *dstr,
74 char ***darray, int *num, int collapse,
77 nmem_strsplit_escape2(nmem, delim, dstr, darray, num, collapse,
81 void nmem_strsplit_escape2(NMEM nmem, const char *delim, const char *dstr,
82 char ***darray, int *num, int collapse,
83 int escape_char, int subst_escape)
86 /* two passes over the input string.. */
90 const char *cp = dstr;
98 while (*cp && strchr(delim, *cp) && *cp != escape_char)
105 while (*cp && !strchr(delim, *cp))
107 if (*cp == escape_char)
113 (*darray)[i] = nmem_strdupn(nmem, cp0, cp - cp0);
116 char *dst = (*darray)[i];
117 const char *src = dst;
120 if (*src == escape_char && src[1])
137 break; /* no items, so stop, *darray=0 already */
139 break; /* second pass, stop */
140 *darray = (char **) nmem_malloc(nmem, *num * sizeof(**darray));
145 char *nmem_text_node_cdata(const xmlNode *ptr_cdata, NMEM nmem)
151 for (ptr = ptr_cdata; ptr; ptr = ptr->next)
152 if (ptr->type == XML_TEXT_NODE)
153 len += xmlStrlen(ptr->content);
154 cdata = (char *) nmem_malloc(nmem, len+1);
156 for (ptr = ptr_cdata; ptr; ptr = ptr->next)
157 if (ptr->type == XML_TEXT_NODE)
158 strcat(cdata, (const char *) ptr->content);
166 * c-file-style: "Stroustrup"
167 * indent-tabs-mode: nil
169 * vim: shiftwidth=4 tabstop=8 expandtab