1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2011 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);
60 void nmem_strsplit(NMEM nmem, const char *delim, const char *dstr,
61 char ***darray, int *num)
63 const char *cp = dstr;
64 for (*num = 0; *cp; (*num)++)
66 while (*cp && strchr(delim, *cp))
70 while (*cp && !strchr(delim, *cp))
78 *darray = (char **) nmem_malloc(nmem, *num * sizeof(**darray));
79 for (cp = dstr; *cp; )
82 while (*cp && strchr(delim, *cp))
87 while (*cp && !strchr(delim, *cp))
89 (*darray)[i++] = nmem_strdupn(nmem, cp0, cp - cp0);
95 char *nmem_text_node_cdata(const xmlNode *ptr_cdata, NMEM nmem)
101 for (ptr = ptr_cdata; ptr; ptr = ptr->next)
102 if (ptr->type == XML_TEXT_NODE)
103 len += xmlStrlen(ptr->content);
104 cdata = (char *) nmem_malloc(nmem, len+1);
106 for (ptr = ptr_cdata; ptr; ptr = ptr->next)
107 if (ptr->type == XML_TEXT_NODE)
108 strcat(cdata, (const char *) ptr->content);
116 * c-file-style: "Stroustrup"
117 * indent-tabs-mode: nil
119 * vim: shiftwidth=4 tabstop=8 expandtab