Rui Hirokawa
hirok****@users*****
2003年 8月 4日 (月) 08:14:29 JST
hirokawa 03/08/04 08:14:29 Modified: mbfl Tag: LIBMBFL_1_0 mbfilter.c mbfilter.h Log: added mbfl_oddlen. Revision Changes Path No revision No revision 1.8.2.4 +44 -0 libmbfl/mbfl/mbfilter.c Index: mbfilter.c =================================================================== RCS file: /cvsroot/php-i18n/libmbfl/mbfl/mbfilter.c,v retrieving revision 1.8.2.3 retrieving revision 1.8.2.4 diff -u -r1.8.2.3 -r1.8.2.4 --- mbfilter.c 1 Aug 2003 08:43:09 -0000 1.8.2.3 +++ mbfilter.c 3 Aug 2003 23:14:29 -0000 1.8.2.4 @@ -766,6 +766,50 @@ return c; } +/* + * oddlen + */ +int +mbfl_oddlen(mbfl_string *string) +{ + int len, n, m, k; + unsigned char *p; + const unsigned char *mbtab; + const mbfl_encoding *encoding; + + encoding = mbfl_no2encoding(string->no_encoding); + if (encoding == NULL || string == NULL) { + return -1; + } + + len = 0; + if (encoding->flag & MBFL_ENCTYPE_SBCS) { + return 0; + } else if (encoding->flag & (MBFL_ENCTYPE_WCS2BE | MBFL_ENCTYPE_WCS2LE)) { + return len % 2; + } else if (encoding->flag & (MBFL_ENCTYPE_WCS4BE | MBFL_ENCTYPE_WCS4LE)) { + return len % 4; + } else if (encoding->mblen_table != NULL) { + mbtab = encoding->mblen_table; + n = 0; + p = string->val; + k = string->len; + /* count */ + if (p != NULL) { + while (n < k) { + m = mbtab[*p]; + n += m; + p += m; + }; + } + return n-k; + } else { + /* how can i do ? */ + return 0; + } + /* NOT REACHED */ +} + int mbfl_strpos( mbfl_string *haystack, 1.6.2.4 +6 -0 libmbfl/mbfl/mbfilter.h Index: mbfilter.h =================================================================== RCS file: /cvsroot/php-i18n/libmbfl/mbfl/mbfilter.h,v retrieving revision 1.6.2.3 retrieving revision 1.6.2.4 diff -u -r1.6.2.3 -r1.6.2.4 --- mbfilter.h 1 Aug 2003 03:14:47 -0000 1.6.2.3 +++ mbfilter.h 3 Aug 2003 23:14:29 -0000 1.6.2.4 @@ -179,6 +179,12 @@ mbfl_strlen(mbfl_string *string); /* + * oddlen + */ +int +mbfl_oddlen(mbfl_string *string); + +/* * strpos */ int