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: 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 * update the documentation in README
* remove the last unnecessary alloc * remove the last unnecessary alloc
@ -11,9 +16,9 @@
* add a README file with short examples of various functions * add a README file with short examples of various functions
27-06-2008: 27-06-2008:
* removed some memorly allocation in xmlGetNode and XMLGetNextElement * removed some memory allocation in xmlGetNode and XMLGetNextElement
* use the filesize for mmap and remove the root node from the xml-id * use the file-size for mmap and remove the root node from the xml-id
* rearange xmlGetNode to work with complicated xml files * rearrange xmlGetNode to work with complicated xml files
* add the xmlMarkId function to save the id before using xmlGetNextElement * add the xmlMarkId function to save the id before using xmlGetNextElement
* speed up xmlGetNextId * 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 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 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 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; void *xnid;
char *s; char *s;

View file

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