diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2007-12-16 12:43:32 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2007-12-16 12:43:32 +0800 |
commit | 81aedaf08d5fb34eddb2cf838a434aed1bfe3a6f (patch) | |
tree | b03e3192666424bfed4eb831eff4eee092d79ff6 /src/libbbsutil | |
parent | 8e5fa100d37547fbbb2862fe8bab431e0d1ea7a6 (diff) | |
download | pttbbs-81aedaf08d5fb34eddb2cf838a434aed1bfe3a6f.tar pttbbs-81aedaf08d5fb34eddb2cf838a434aed1bfe3a6f.tar.gz pttbbs-81aedaf08d5fb34eddb2cf838a434aed1bfe3a6f.tar.bz2 pttbbs-81aedaf08d5fb34eddb2cf838a434aed1bfe3a6f.tar.lz pttbbs-81aedaf08d5fb34eddb2cf838a434aed1bfe3a6f.tar.xz pttbbs-81aedaf08d5fb34eddb2cf838a434aed1bfe3a6f.tar.zst pttbbs-81aedaf08d5fb34eddb2cf838a434aed1bfe3a6f.zip |
- disable interupting ANSI inside DBCS characters (for UTF-8 or
non-DBCS clients)
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@3688 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'src/libbbsutil')
-rw-r--r-- | src/libbbsutil/string.c | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/libbbsutil/string.c b/src/libbbsutil/string.c index 695d65ab..b2e7612e 100644 --- a/src/libbbsutil/string.c +++ b/src/libbbsutil/string.c @@ -206,6 +206,67 @@ strip_nonebig5(unsigned char *str, int maxlen) str[len]='\0'; } +int DBCS_RemoveIntrEscape(unsigned char *buf, int *len) +{ + register int isInAnsi = 0, isInDBCS = 0; + int l = 0, i = 0, oldl, iansi = 0; + + if (len) l = *len; else l = strlen((const char*)buf); + oldl = l; + + for (i = 0; i < l; i++) + { + if (buf[i] == ESC_CHR && !isInAnsi) + { + // new escape + isInAnsi = 1; + iansi = i; + continue; + } + + // character + if (isInAnsi) + { + // closing ANSI section? + switch (isInAnsi) + { + case 1: // normal ANSI + if (buf[i] == '[') + isInAnsi = 2; + else + isInAnsi = 0; // unknown command + break; + + case 2: + if (isEscapeParam(buf[i])) + break; + else + isInAnsi = 0; + break; + } + if (isInAnsi == 0 && isInDBCS && i+1 < l) + { + // interupting ANSI closed, let's modify the string + int sz = i + 1 - iansi; // size to move + memmove(buf+iansi, buf+i+1, l-i-1); + l -= sz; + i = iansi-1; // for the ++ in loop + } + } else if (isInDBCS) { + // not ANSI but in DBCS. finished one char. + isInDBCS = 0; + } else if (buf[i] >= 0x80) { + // DBCS lead. + isInDBCS = 1; + } else { + // normal character. + } + } + + if(len) *len = l; + return (oldl != l) ? 1 : 0; +} + /* ----------------------------------------------------- */ /* 字串檢查函數:英文、數字、檔名、E-mail address */ /* ----------------------------------------------------- */ |