Internationalization and localization tools


Locale-Sensitive C/C++ String Operation Function

size_t strlen(const char *string);

size_t wcslen(const wchar_t *string);

size_t _mbslen(const unsigned char *string);

size_t _mbstrlen(const char *string);

size_t _tcslen(const _TXCHAR *string);

size_t _tcsclen(const _TXCHAR *string);

Internationalization (I18n) Function Overview

The strlen function returns the number of single-byte characters in string.

wcslen is the wide version of the function; its parameter is a wide-character string and the return is the number of wide characters.

On Windows platforms, _mbslen and _mbstrlen are the multibyte versions of strlen, returning the number of multibyte characters. _mbslen interprets the multibyte-characters according to the multibyte code page currently in use; whereas _mbstrlen tests for multibyte-character validity and interprets multibyte-characters according to the LC_CTYPE category setting of the current locale.

_tcslen and _tcsclen are the Generic versions of the function; when the Windows _MBCS compiler flag is set, _tcslen maps to strlen and _tcsclen maps to _mbslen. When the Windows _UNICODE flag is set, the Generic functions both map to wcslen.

I18n Issues

Use the appropriate version of the function as required for internationalization support, noting the following:

On ANSI platforms, convert the multibyte string to a wide-character string, and then call wcslen.

On Windows MBCS platforms, ensure that the current locale and the multibyte code page are set correctly.

On Windows MBCS platforms, choose _tcsclen rather than _tcslen when desiring the number of multibyte characters, since _tcsclen will map to _mbslen when the _MBCS compiler flag is set, whereas _tcslen will map to strlen.

Recommended Replacements*

On Windows platforms, a more secure string function is recommended. However, there are differences in the handling of multibyte-character strings which will need to be considered before switching. For more details, click on one of the secure functions in the following table: they are listed as the first choices for the Windows rulesets.

*If you're already using the recommended function, see I18n Issues for other reasons why Globalyzer is detecting the function.

Locale-Sensitive C/C++ String Operation Functions

 

Lingoport internationalization and localization services and software