mirror of
https://github.com/mdbtools/mdbtools.git
synced 2026-03-10 00:20:54 +08:00
added like operator and handling of string sargs
Added index stuff to HACKING file Misc. mdb-sql updates
This commit is contained in:
38
src/libmdb/like.c
Normal file
38
src/libmdb/like.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int likecmp(char *s, char *r)
|
||||
{
|
||||
int i, ret;
|
||||
|
||||
switch (r[0]) {
|
||||
case '\0':
|
||||
if (s[0]=='\0') {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
case '_':
|
||||
/* skip one character */
|
||||
return likecmp(&s[1],&r[1]);
|
||||
case '%':
|
||||
/* skip any number of characters */
|
||||
/* the strlen(s)+1 is important so the next call can */
|
||||
/* if there are trailing characters */
|
||||
for(i=0;i<strlen(s)+1;i++) {
|
||||
if (likecmp(&s[i],&r[1])) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
default:
|
||||
for(i=0;i<strlen(r);i++) {
|
||||
if (r[i]=='_' || r[i]=='%') break;
|
||||
}
|
||||
if (strncmp(s,r,i)) {
|
||||
return 0;
|
||||
} else {
|
||||
ret = likecmp(&s[i],&r[i]);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user