2 * Copyright (C) 1995-2006, Index Data ApS
3 * See the file LICENSE for details.
5 * $Id: nmemsdup.c,v 1.6 2006-05-02 20:47:45 adam Exp $
10 * \brief Implements NMEM dup utilities
20 #include <libxml/tree.h>
23 char *nmem_strdup (NMEM mem, const char *src)
25 char *dst = (char *)nmem_malloc (mem, strlen(src)+1);
30 char *nmem_strdupn (NMEM mem, const char *src, size_t n)
32 char *dst = (char *)nmem_malloc (mem, n+1);
38 int *nmem_intdup(NMEM mem, int v)
40 int *dst = (int*) nmem_malloc (mem, sizeof(int));
45 void nmem_strsplit_blank(NMEM nmem, const char *dstr, char ***darray, int *num)
47 nmem_strsplit(nmem, " ", dstr, darray, num);
50 void nmem_strsplit(NMEM nmem, const char *delim, const char *dstr,
51 char ***darray, int *num)
53 const char *cp = dstr;
54 for (*num = 0; *cp; (*num)++)
56 while (*cp && strchr(delim, *cp))
60 while (*cp && !strchr(delim, *cp))
68 *darray = nmem_malloc(nmem, *num * sizeof(**darray));
69 for (cp = dstr; *cp; )
72 while (*cp && strchr(delim, *cp))
77 while (*cp && !strchr(delim, *cp))
79 (*darray)[i++] = nmem_strdupn(nmem, cp0, cp - cp0);
85 char *nmem_text_node_cdata(const void *ptr_cdata, NMEM nmem)
91 for (ptr = (const xmlNode *) ptr_cdata; ptr; ptr = ptr->next)
92 if (ptr->type == XML_TEXT_NODE)
93 len += xmlStrlen(ptr->content);
94 cdata = (char *) nmem_malloc(nmem, len+1);
96 for (ptr = (const xmlNode *) ptr_cdata; ptr; ptr = ptr->next)
97 if (ptr->type == XML_TEXT_NODE)
98 strcat(cdata, (const char *) ptr->content);
106 * indent-tabs-mode: nil
108 * vim: shiftwidth=4 tabstop=8 expandtab