summaryrefslogtreecommitdiffstats
path: root/stringbuf.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2005-09-26 13:56:21 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2005-09-26 13:56:21 +0000
commit7fd25c33186a12ee1e9b855dc7cc33b0cf9a3ad3 (patch)
treeda96c0e8114516ee4734e9e832a5b317f2d8b772 /stringbuf.c
parent58d50e94455c52385595146e9fa19563b162e912 (diff)
downloadrsyslog-7fd25c33186a12ee1e9b855dc7cc33b0cf9a3ad3.tar.gz
rsyslog-7fd25c33186a12ee1e9b855dc7cc33b0cf9a3ad3.tar.xz
rsyslog-7fd25c33186a12ee1e9b855dc7cc33b0cf9a3ad3.zip
added the "startwith" property-filter comparison operation
Diffstat (limited to 'stringbuf.c')
-rwxr-xr-xstringbuf.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/stringbuf.c b/stringbuf.c
index 1f6d6316..738a1f81 100755
--- a/stringbuf.c
+++ b/stringbuf.c
@@ -371,6 +371,37 @@ int rsCStrCStrCmp(rsCStrObj *pCS1, rsCStrObj *pCS2)
}
+/* check if a CStr object starts with a sz-type string. This function
+ * is initially written to support the "startswith" property-filter
+ * comparison operation. Maybe it also has other needs.
+ * rgerhards 2005-09-26
+ */
+int rsCStrStartsWithSzStr(rsCStrObj *pCS1, char *psz, int iLenSz)
+{
+ rsCHECKVALIDOBJECT(pCS1, OIDrsCStr);
+ assert(psz != NULL);
+ assert(iLenSz == strlen(psz)); /* just make sure during debugging! */
+ if(pCS1->iStrLen >= iLenSz) {
+ /* we are using iLenSz below, because we need to check
+ * iLenSz characters at maximum (start with!)
+ */
+ if(iLenSz == 0)
+ return 0; /* yes, it starts with a zero-sized string ;) */
+ else { /* we now have something to compare, so let's do it... */
+ register int i;
+ for(i = 0 ; i < iLenSz ; ++i) {
+ if(pCS1->pBuf[i] != psz[i])
+ return pCS1->pBuf[i] - psz[i];
+ }
+ /* if we arrive here, the string actually starts with psz */
+ return 0;
+ }
+ }
+ else
+ return -1; /* pCS1 is less then psz */
+}
+
+
/* compare a rsCStr object with a classical sz string. This function
* is almost identical to rsCStrZsStrCmp(), but it also takes an offset
* to the CStr object from where the comparison is to start.