_mbsbtype

De RAD Studio
Aller à : navigation, rechercher

Remonter à string.h - Index


Header File

mbstring.h

Category

Classification Routines

Prototype

int _mbsbtype(const unsigned char *str, size_t nbyte);

Description

The nbyte argument specifies the number of bytes from the start of the zero-based string.

The _mbsbtype function inspects the argument str to determine whether the byte at the position specified by nbyte is a single-byte character, or whether it is the leadbyte or trailing byte in a multibyte character. The _mbsbtype function can determine whether the byte pointed at is an invalid character or a NULL byte.

Any invalid bytes in str before nbyte are ignored.

Return Value

The value that _mbsbtype returns is one of the following manifest constants, defined in mbctype.h.

Example

#include <mbstring.h>
#include <mbctype.h>
int count_chars(char* input)
{
  int type, i = 0, chars = 0;

  while (input[i])
  {
    /* Obtain the type of the i-th char in the string */ 
    type = _mbsbtype(input, i);

    /* Consider single and MBCS chars as whole chars */
    switch (type) {
      case _MBC_LEAD:
      case _MBC_SINGLE:
        chars++;
        break;
      case _MBC_ILLEGAL:
        return -1;
    }

    i++;
  }

  /* The number of chars */
  return chars;
}