summaryrefslogtreecommitdiffstats
path: root/mbbsd/read.c
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-12-10 18:48:33 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2007-12-10 18:48:33 +0800
commit9c92e958fd4f6a5d25cbab9d80e0fee8aa70c478 (patch)
tree98fd30c1a6fd39074cffa8eea68f6bea851b6361 /mbbsd/read.c
parentd1ed75451dc4644c7c6429d977fe836d367cc5d4 (diff)
downloadpttbbs-9c92e958fd4f6a5d25cbab9d80e0fee8aa70c478.tar
pttbbs-9c92e958fd4f6a5d25cbab9d80e0fee8aa70c478.tar.gz
pttbbs-9c92e958fd4f6a5d25cbab9d80e0fee8aa70c478.tar.bz2
pttbbs-9c92e958fd4f6a5d25cbab9d80e0fee8aa70c478.tar.lz
pttbbs-9c92e958fd4f6a5d25cbab9d80e0fee8aa70c478.tar.xz
pttbbs-9c92e958fd4f6a5d25cbab9d80e0fee8aa70c478.tar.zst
pttbbs-9c92e958fd4f6a5d25cbab9d80e0fee8aa70c478.zip
improved dbcs_strcasestr
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3662 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/read.c')
-rw-r--r--mbbsd/read.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/mbbsd/read.c b/mbbsd/read.c
index e30c60c2..eb58e360 100644
--- a/mbbsd/read.c
+++ b/mbbsd/read.c
@@ -408,9 +408,12 @@ mail_forward(const fileheader_t * fhdr, const char *direct, int mode)
}
#endif
+// return: 1 - found, 0 - fail.
inline static int
dbcs_strcasestr(const char* pool, const char *ptr)
{
+#if 0
+ // old method
int len = strlen(ptr);
while(*pool)
@@ -428,6 +431,50 @@ dbcs_strcasestr(const char* pool, const char *ptr)
pool ++;
}
return 0;
+
+#endif
+
+ int i = 0, i2 = 0, found = 0,
+ szpool = strlen(pool),
+ szptr = strlen(ptr);
+
+ for (i = 0; i <= szpool-szptr; i++)
+ {
+ found = 1;
+
+ // compare szpool[i..szptr] with ptr
+ for (i2 = 0; i2 < szptr; i2++)
+ {
+ if (pool[i + i2] > 0)
+ {
+ // ascii
+ if (ptr[i2] < 0 ||
+ tolower(ptr[i2]) != tolower(pool[i+i2]))
+ {
+ // printf("break on ascii (i=%d, i2=%d).\n", i, i2);
+ found = 0;
+ break;
+ }
+ } else {
+ // non-ascii
+ if (ptr[i2] != pool[i+i2] ||
+ ptr[i2+1] != pool[i+i2+1])
+ {
+ // printf("break on non-ascii (i=%d, i2=%d).\n", i, i2);
+ found = 0;
+ break;
+ }
+ i2 ++;
+ }
+ }
+
+ if (found) break;
+
+ // next iteration: if target is DBCS, skip one more byte.
+ if (pool[i] < 0)
+ i++;
+ }
+ return found;
}
static int