1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2009 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 int *nmem_intdup(NMEM mem, int v)
43 int *dst = (int*) nmem_malloc (mem, sizeof(int));
48 void nmem_strsplit_blank(NMEM nmem, const char *dstr, char ***darray, int *num)
50 nmem_strsplit(nmem, " ", dstr, darray, num);
53 void nmem_strsplit(NMEM nmem, const char *delim, const char *dstr,
54 char ***darray, int *num)
56 const char *cp = dstr;
57 for (*num = 0; *cp; (*num)++)
59 while (*cp && strchr(delim, *cp))
63 while (*cp && !strchr(delim, *cp))
71 *darray = (char **) nmem_malloc(nmem, *num * sizeof(**darray));
72 for (cp = dstr; *cp; )
75 while (*cp && strchr(delim, *cp))
80 while (*cp && !strchr(delim, *cp))
82 (*darray)[i++] = nmem_strdupn(nmem, cp0, cp - cp0);
88 char *nmem_text_node_cdata(const xmlNode *ptr_cdata, NMEM nmem)
94 for (ptr = ptr_cdata; ptr; ptr = ptr->next)
95 if (ptr->type == XML_TEXT_NODE)
96 len += xmlStrlen(ptr->content);
97 cdata = (char *) nmem_malloc(nmem, len+1);
99 for (ptr = ptr_cdata; ptr; ptr = ptr->next)
100 if (ptr->type == XML_TEXT_NODE)
101 strcat(cdata, (const char *) ptr->content);
109 * indent-tabs-mode: nil
111 * vim: shiftwidth=4 tabstop=8 expandtab