diff options
-rw-r--r-- | pttbbs/common/sys/string.c | 8 | ||||
-rw-r--r-- | pttbbs/include/cmsys.h | 1 |
2 files changed, 9 insertions, 0 deletions
diff --git a/pttbbs/common/sys/string.c b/pttbbs/common/sys/string.c index dbcd396a..7b071ba7 100644 --- a/pttbbs/common/sys/string.c +++ b/pttbbs/common/sys/string.c @@ -345,6 +345,14 @@ int DBCS_Status(const char *dbcstr, int pos) return sts; } +void DBCS_safe_trim(char *dbcstr) +{ + int len = strlen(dbcstr); + if (len < 1) return; + if (DBCS_Status(dbcstr, len-1) == DBCS_LEADING) + dbcstr[len-1] = 0; +} + /** * DBCS_strcasestr(pool, ptr): 在字串 pool 中尋找 ptr (只忽略英文大小寫) */ diff --git a/pttbbs/include/cmsys.h b/pttbbs/include/cmsys.h index 89ad93d5..7704191c 100644 --- a/pttbbs/include/cmsys.h +++ b/pttbbs/include/cmsys.h @@ -106,6 +106,7 @@ extern unsigned StringHash(const char *s); /* DBCS utilities */ extern int DBCS_RemoveIntrEscape(unsigned char *buf, int *len); extern int DBCS_Status(const char *dbcstr, int pos); +extern void DBCS_safe_trim(char *dbcstr); extern char * DBCS_strcasestr(const char* pool, const char *ptr); extern size_t str_iconv( const char *fromcode, /* charset of source string */ |