Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <stdlib.h>
        or
    #include <mbstring.h>
    int mblen( const char *s, size_t n );
    int _fmblen( const char __far *s, size_t n );

Description:
    The mblen function determines the number of bytes comprising the
    multibyte character pointed to by s.  At most n bytes of the array
    pointed to by s will be examined.

    The _fmblen function is a data model independent form of the mblen
    function.  It accepts far pointer arguments and returns a far pointer.
     It is most useful in mixed memory model applications.

Returns:
    If s is a NULL pointer, the mblen function returns zero if multibyte
    character encodings are not state dependent, and non-zero otherwise.  If
    s is not a NULL pointer, the mblen function returns:

    Value     Meaning

0
    if s points to the null character

len
    the number of bytes that comprise the multibyte character (if the next n
    or fewer bytes form a valid multibyte character)

-1
    if the next n bytes do not form a valid multibyte character



Example:
    #include <stdio.h>
    #include <mbctype.h>


    const char chars[] = {
        ' ',
        '.',
        '1',
        'A',
        0x81,0x40, /* double-byte space */
        0x82,0x60, /* double-byte A */
        0x82,0xA6, /* double-byte Hiragana */
        0x83,0x42, /* double-byte Katakana */
        0xA1,      /* single-byte Katakana punctuation */
        0xA6,      /* single-byte Katakana alphabetic */
        0xDF,      /* single-byte Katakana alphabetic */
        0xE0,0xA1, /* double-byte Kanji */
        0x00
    };

    void main()
      {
        int         i, j, k;

        _setmbcp( 932 );
        printf( "Character encodings are %sstate dependent\n",
                ( mblen( NULL, MB_CUR_MAX ) ) ? "" : "not " );
        j = 1;
        for( i = 0; j > 0; i += j ) {
          j = mblen( &chars[i], MB_CUR_MAX );
          printf( "%d bytes in character ", j );
          if( j == 0 ) {
            k = 0;
          } else if ( j == 1 ) {
            k = chars[i];
          } else if( j == 2 ) {
            k = chars[i]<<8 | chars[i+1];
          }
          printf( "(%#6.4x)\n", k );
        }
      }

    produces the following:

    Character encodings are not state dependent
    1 bytes in character (0x0020)
    1 bytes in character (0x002e)
    1 bytes in character (0x0031)
    1 bytes in character (0x0041)
    2 bytes in character (0x8140)
    2 bytes in character (0x8260)
    2 bytes in character (0x82a6)
    2 bytes in character (0x8342)
    1 bytes in character (0x00a1)
    1 bytes in character (0x00a6)
    1 bytes in character (0x00df)
    2 bytes in character (0xe0a1)
    0 bytes in character (  0000)

Classification:
    mblen is ANSI, _fmblen is not ANSI

Systems:
     mblen - All, Netware

    _fmblen - DOS, Windows, Win386, Win32, OS/2 1.x(all), OS/2-32

See Also:
    _mbccmp, _mbccpy, _mbcicmp, _mbcjistojms, _mbcjmstojis, _mbclen,
    _mbctohira, _mbctokata, _mbctolower, _mbctombb, _mbctoupper, mbrlen,
    mbrtowc, mbsrtowcs, mbstowcs, mbtowc, sisinit, wcrtomb, wcsrtombs,
    wcstombs, wctob, wctomb

See Also: _mbcjistojms _mbcjmstojis

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson