1
0
Fork 0

* fix a problem caused by removing the last unnecessary alloc

* strip leading-, and trailing spaces from the string before comparing
 * fix a problem where trailing spaces weren't removed
This commit is contained in:
ehofman 2008-07-01 12:15:46 +00:00
parent 177d06e9ec
commit 67ca3c0307
3 changed files with 61 additions and 24 deletions

View file

@ -1,5 +1,10 @@
01-07-2008
* fix a problem caused by removing the last unnecessary alloc
* strip leading-, and trailing spaces from the string before comparing
* fix a problem where trailing spaces weren't removed
30-06-2008:
* some small changes; fix some typo's en fix a small memory leak
* some small changes; fix some typo's and fix a small memory leak
* update the documentation in README
* remove the last unnecessary alloc
@ -11,9 +16,9 @@
* add a README file with short examples of various functions
27-06-2008:
* removed some memorly allocation in xmlGetNode and XMLGetNextElement
* use the filesize for mmap and remove the root node from the xml-id
* rearange xmlGetNode to work with complicated xml files
* removed some memory allocation in xmlGetNode and XMLGetNextElement
* use the file-size for mmap and remove the root node from the xml-id
* rearrange xmlGetNode to work with complicated xml files
* add the xmlMarkId function to save the id before using xmlGetNextElement
* speed up xmlGetNextId

View file

@ -26,7 +26,8 @@ While it is certainly possible to access every node directly by calling the
xmlGetNode(Int/Double/String) functions, when more than one node need to be
gathered from a parent node it is advised to get the id of the parent node
and work from there. This is because the XML-id holds the boundaries of the
(parent)node which limits the searching area causing improved searching speed.
(parent)node which limits the searching area resulting in improved searching
speed.
{
void *xnid;
char *s;

View file

@ -205,7 +205,17 @@ xmlCompareString(const void *id, const char *s)
if (xid && xid->len && s && (strlen(s) > 0))
{
ret = strncasecmp(xid->start, s, xid->len);
char *ps, *pe;
ps = xid->start;
pe = ps + xid->len;
pe--;
while ((ps<pe) && isspace(*ps)) ps++;
while ((pe>ps) && isspace(*pe)) pe--;
pe++;
ret = strncasecmp(ps, s, pe-ps);
}
return ret;
@ -219,12 +229,21 @@ xmlCompareNodeString(const void *id, const char *path, const char *s)
if (xid && xid->len && path && s && (strlen(s) > 0))
{
char *str, *ps, *pe;
size_t rlen;
char *str;
rlen = strlen(path);
str = __xmlGetNode(xid->start, xid->len, path, &rlen);
if (str) ret = strncasecmp(str, s, rlen);
ps = str;
pe = ps + rlen;
pe--;
while ((ps<pe) && isspace(*ps)) ps++;
while ((pe>ps) && isspace(*pe)) pe--;
pe++;
if (str) ret = strncasecmp(pe, s, pe-ps);
}
return ret;
@ -241,19 +260,20 @@ xmlGetNodeString(void *id, const char *path)
str = __xmlCopyNode(xid->start, xid->len, path);
if (str)
{
char *ps, *pe, *pem;
char *ps, *pe, *pend;
int slen;
slen = strlen(str);
ps = str;
pe = pem = ps+slen;
pend = ps+slen;
pe = pend-1;
while ((ps<pe) && isspace(*ps)) ps++;
while ((pe>ps) && isspace(*pe)) pe--;
if (pe<pem) *++pe = 0;
*++pe = 0;
slen = (pe-ps);
if ((ps>str) && slen) memmove(str, ps, slen+1);
if (slen && (ps>str)) memmove(str, ps, slen);
else if (!slen) *str = 0;
}
}
@ -272,20 +292,21 @@ xmlGetString(void *id)
str = malloc(xid->len+1);
if (str)
{
char *ps, *pe, *pem;
char *ps, *pe, *pend;
int slen;
slen = xid->len;
memcpy(str, xid->start, slen);
*(str+slen) = 0;
ps = str;
pe = pem = ps+slen;
pend = ps+slen;
pe = pend-1;
*pend = 0;
while ((ps<pe) && isspace(*ps)) ps++;
while ((pe>ps) && isspace(*pe)) pe--;
if (pe<pem) *++pe = 0;
if (pe<pend) *++pe = 0;
slen = (pe-ps);
if ((ps>str) && slen) memmove(str, ps, slen+1);
else if (!slen) *str = 0;
@ -404,7 +425,7 @@ xmlGetNumElements(void *id, const char *path)
{
unsigned int clen;
char *p, *pathname;
char *pname, *nname;
char *nname;
pathname = (char *)path;
if (*path == '/') pathname++;
@ -413,7 +434,7 @@ xmlGetNumElements(void *id, const char *path)
if (nname)
{
clen = nname-pathname;
p = __xmlGetNode(xid->start, xid->len, path, &clen);
p = __xmlGetNode(xid->start, xid->len, pathname, &clen);
}
else
{
@ -471,22 +492,31 @@ __xmlGetNode(char *start, size_t len, const char *path, size_t *rlen)
{
char *ret = 0;
if (len)
if (len && rlen && *rlen)
{
char last_node = 0;
char *ptr, *name;
int plen;
size_t plen, slen;
slen = *rlen;
name = (char *)path;
if (*name == '/') name++; /* skip the leading '/' character */
if (*name == '/')
{
name++; /* skip the leading '/' character */
slen--;
}
ptr = strchr(name, '/');
if (!ptr)
{
last_node = 1;
ptr = name + *rlen;
plen = slen;
}
else
{
plen = ptr++ - name;
slen -= (ptr - name);
}
plen = ptr - name;
if (plen)
{
@ -532,7 +562,8 @@ __xmlGetNode(char *start, size_t len, const char *path, size_t *rlen)
}
else
{
ret = __xmlGetNode(cur, len, ptr+1, rlen);
*rlen = slen;
ret = __xmlGetNode(cur, len, ptr, rlen);
}
}
}