Multi-byte String Handling Sample

Description

C++ supports the use of wide characters via the wchar_t type. These are composed of one or more bytes. A group of one or more bytes in an external format (such as a disk file) is called a multibyte character, and these can be translated to and from wide characters using codecvt::in() and codecvt::out().

If you have a stream of bytes in external format, then one of the useful pieces of information to know about that stream is how many internal characters (such as ones of wchar_t type) are represented, for a given sequence of external bytes. The length() function of codecvt can be used for this purpose.

Concept

The sample defines a wildcard matching function, so that for example a pattern like a?c will match input of abc. The pattern is specified using a wchar_t* string, and the string the pattern is to match against is a char* string. This situation would arise, for example, in a case where a wide character pattern was being matched against strings expressed in external (multibyte) format.

codecvt::length() and codecvt::in() are used to determine how many characters in external format (char*) make up a single character in internal format (wchar_t*).

Supported
Supported
Supported