diff options
author | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-04-16 01:08:07 +0800 |
---|---|---|
committer | piaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-04-16 01:08:07 +0800 |
commit | a38ce8fbc7b7b18ad75f86278fe25fd85ba485d2 (patch) | |
tree | 5a227cdba379a203155bbaf91b8b2323a2130a3c /common/sys | |
parent | db9187feb31e50ed2fbe78f7fd73bf8d37bf0edc (diff) | |
download | pttbbs-a38ce8fbc7b7b18ad75f86278fe25fd85ba485d2.tar pttbbs-a38ce8fbc7b7b18ad75f86278fe25fd85ba485d2.tar.gz pttbbs-a38ce8fbc7b7b18ad75f86278fe25fd85ba485d2.tar.bz2 pttbbs-a38ce8fbc7b7b18ad75f86278fe25fd85ba485d2.tar.lz pttbbs-a38ce8fbc7b7b18ad75f86278fe25fd85ba485d2.tar.xz pttbbs-a38ce8fbc7b7b18ad75f86278fe25fd85ba485d2.tar.zst pttbbs-a38ce8fbc7b7b18ad75f86278fe25fd85ba485d2.zip |
- (internal) visio: add columned output API.
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4170 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'common/sys')
-rw-r--r-- | common/sys/string.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/common/sys/string.c b/common/sys/string.c index b152ac63..881a0e04 100644 --- a/common/sys/string.c +++ b/common/sys/string.c @@ -134,6 +134,50 @@ strip_ansi(char *dst, const char *src, enum STRIP_FLAG mode) return count; } +/** + * query the offset of nth non-ANSI element in s + * if string is less then nth, return missing blanks in negative value. + */ +int +strat_ansi(int count, const char *s) +{ + register int mode = 0; + const char *os = s; + + for (; count > 0 && *s; ++s) + { + // 0 - no ansi, 1 - [, 2 - param+cmd + switch (mode) + { + case 0: + if (*s == ESC_CHR) + mode = 1; + else + count --; + break; + + case 1: + if (*s == '[') + mode = 2; + else + mode = 0; // unknown command + break; + + case 2: + if (isEscapeParam(*s)) + continue; + else if (isEscapeCommand(*s)) + mode = 0; + else + mode = 0; + break; + } + } + if (count > 0) + return -count; + return s - os; +} + int strlen_noansi(const char *s) { |