Internationalization and localization tools


Locale-Sensitive Length Functions

size_t _strncnt(const char *strSource, size_t number);

size_t _mbsnbcnt(const unsigned char *strSource, size_t number);

size_t _mbsnccnt(const unsigned char *strSource, size_t number);

size_t _wcsncnt(const wchar_t *strSource, size_t number);

size_t _tcsnbcnt(const _TXCHAR *strSource, size_t number);

size_t _tcsnccnt(const _TXCHAR *strSource, size_t number);

Internationalization (I18n) Function Overview

The _strncnt function returns the number of characters in the first number bytes of the single byte strSource string.

_mbsnbcnt is the multibyte character version that returns the number of bytes in the multibyte string; whereas _mbsnccnt returns the number of multibyte characters in the string.

_wcsncnt is the wide-character version that returns the number of wide characters in the wide-character string.

_tcsnbcnt and _tcsnccnt are the Generic versions of the function; when the Windows _MBCS compiler flag is set, _tcsnbcnt maps to _mbsnbcnt and _tcsnccnt maps to _mbsnccnt. When the Windows _UNICODE flag is set, the Generic functions both map to _wcsncnt.

I18n Issues

Special care must be taken with the number parameter. See Locale-Sensitive Length Functions for a complete discussion of the issues involved with functions that pass length parameters.

In multibyte applications care must be taken to call the correct version of this function. There are 2 versions of this function, one that returns the number of multibyte characters (_mbsnccnt) and one that returns the number of bytes (_mbsnbcnt). A typical use of these functions would be to get a count of bytes or characters to pass on to another function such as _mbsncpy. Be sure to use the correct call, for example with _mbsncpy you would want to use _mbsnccnt since it expects a number of multibyte characters, not bytes.

For Windows MBCS platforms, ensure that the multibyte code page is set properly, as _mbsnbcnt and _mbsnccnt depend on it. By default, the multibyte code page is set to the system-default ANSI code page obtained from the operating system at program startup. Use _getmbcp and _setmbcp to query or change the current multibyte code page, respectively.

Recommended Function Replacements

Microsoft Windows MBCS_mbsnbcnt or _mbsnccnt
Microsoft Windows Unicode_wcsncnt
Microsoft Windows Generic_tcsbcnt or _tcsccnt

Locale-Sensitive Length Functions

 

Lingoport internationalization and localization services and software