diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2008-02-22 18:13:01 +0000 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2008-02-22 18:13:01 +0000 |
commit | 79ca6100e64b3fff6f52444f121ee1f7642a7b04 (patch) | |
tree | f45da675d90c84b8b863cd0bc00f5ee839a560ad /stringbuf.c | |
parent | 75e9a2dc69bad2fe10cc60d801019731069005cf (diff) | |
download | rsyslog-79ca6100e64b3fff6f52444f121ee1f7642a7b04.tar.gz rsyslog-79ca6100e64b3fff6f52444f121ee1f7642a7b04.tar.bz2 rsyslog-79ca6100e64b3fff6f52444f121ee1f7642a7b04.zip |
worked a bit on var_t data type conversion
Diffstat (limited to 'stringbuf.c')
-rwxr-xr-x | stringbuf.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/stringbuf.c b/stringbuf.c index a54fe1bd..d1e69abf 100755 --- a/stringbuf.c +++ b/stringbuf.c @@ -718,6 +718,37 @@ int rsCStrOffsetSzStrCmp(cstr_t *pCS1, size_t iOffset, uchar *psz, size_t iLenSz } +/* check if the string can be converted to a number. Returns 1 if that's possible + * and 0 otherwise. + */ +int rsCStrCanConvertToNumber(cstr_t *pStr) +{ + int i; + int ret = 1; + + if(pStr->iStrLen == 0) { + /* can be converted to 0! (by convention) */ + goto finalize_it; + } + + /* we have a string, so let's check its syntax */ + if(pStr->pBuf[0] == '+' || pStr->pBuf[0] == '-') { + i = 1; /* skip that char */ + } else { + i = 0; /* start from the beginning */ + } + + while(i < pStr->iStrLen && isdigit(pStr->pBuf[i])) + ++i; + + if(i < pStr->iStrLen) /* non-digits before end of string? */ + ret = 0; /* than we can not convert */ + +finalize_it: + return ret; +} + + /* compare a rsCStr object with a classical sz string. * Just like rsCStrCStrCmp, just for a different data type. * There must not only the sz string but also its length be |