Internationalization and localization tools


Locale-Sensitive Length Function

char* _strnset(char* string, int c, size_t count);

unsigned char* _mbsnbset(unsigned char* string, int c, size_t count);

unsigned char* _mbsnset(unsigned char* string, unsigned int c, size_t count);

wchar_t* _wcsnset(wchar_t* string, wchar_t c, size_t count);

_TXCHAR* _tcsnset(const _TXCHAR* string, int c, size_t count);

_TXCHAR* _tcsncset(const _TXCHAR* string, _TINT c, size_t count);

Internationalization (I18n) Function Overview

The _strnset function fills, at most, the first count characters of string with the character c, except for the terminating null character. It returns a pointer to the modified string.

_mbsnbset is the multibyte character version that treats count as a single-byte value, setting count bytes of the multibyte string, regardless the size of the multibyte character stored in c; whereas _mbsnset treats count as a multibyte-character count and so fills string with count copies of the multibyte character c, which may occupy one or two bytes.

_wcsnset is the wide-character version; its string argument and return value are wide-character strings.

_tcsnset and _tcsncset are the Generic versions of the function; when the Windows _MBCS compiler flag is set, _tcsnset maps to _mbsnbset and _tcsncset maps to _mbsnset. When the Windows _UNICODE flag is set, the Generic functions both map to _wcsncset.

I18n Issues

Special care must be taken with the size 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 to call if the character c being passed is a character larger than one byte (_mbsnset) and one to call if the character c being passed is a one byte character (_mbsnbset). Be sure to use the appropriate call. Also pay attention to the count parameter which should contain the number of characters and not bytes for the multibyte function _mbsnset.

For Windows MBCS platforms, ensure that the multibyte code page is set properly, as _mbsnset and _mbsnbset 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 Replacements*

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

Locale-Sensitive Length Functions

 

Lingoport internationalization and localization services and software