Copyright (C) 2000-2012 |
GNU Info (libc.info)Non-reentrant Character ConversionNon-reentrant Conversion of Single Characters --------------------------------------------- - Function: int mbtowc (wchar_t *restrict RESULT, const char *restrict STRING, size_t SIZE) The `mbtowc' ("multibyte to wide character") function when called with non-null STRING converts the first multibyte character beginning at STRING to its corresponding wide character code. It stores the result in `*RESULT'. `mbtowc' never examines more than SIZE bytes. (The idea is to supply for SIZE the number of bytes of data you have in hand.) `mbtowc' with non-null STRING distinguishes three possibilities: the first SIZE bytes at STRING start with valid multibyte characters, they start with an invalid byte sequence or just part of a character, or STRING points to an empty string (a null character). For a valid multibyte character, `mbtowc' converts it to a wide character and stores that in `*RESULT', and returns the number of bytes in that character (always at least 1 and never more than SIZE). For an invalid byte sequence, `mbtowc' returns -1. For an empty string, it returns 0, also storing `'\0'' in `*RESULT'. If the multibyte character code uses shift characters, then `mbtowc' maintains and updates a shift state as it scans. If you call `mbtowc' with a null pointer for STRING, that initializes the shift state to its standard initial value. It also returns nonzero if the multibyte character code in use actually has a shift state. Note: Shift State. - Function: int wctomb (char *STRING, wchar_t WCHAR) The `wctomb' ("wide character to multibyte") function converts the wide character code WCHAR to its corresponding multibyte character sequence, and stores the result in bytes starting at STRING. At most `MB_CUR_MAX' characters are stored. `wctomb' with non-null STRING distinguishes three possibilities for WCHAR: a valid wide character code (one that can be translated to a multibyte character), an invalid code, and `L'\0''. Given a valid code, `wctomb' converts it to a multibyte character, storing the bytes starting at STRING. Then it returns the number of bytes in that character (always at least 1 and never more than `MB_CUR_MAX'). If WCHAR is an invalid wide character code, `wctomb' returns -1. If WCHAR is `L'\0'', it returns `0', also storing `'\0'' in `*STRING'. If the multibyte character code uses shift characters, then `wctomb' maintains and updates a shift state as it scans. If you call `wctomb' with a null pointer for STRING, that initializes the shift state to its standard initial value. It also returns nonzero if the multibyte character code in use actually has a shift state. Note: Shift State. Calling this function with a WCHAR argument of zero when STRING is not null has the side-effect of reinitializing the stored shift state _as well as_ storing the multibyte character `'\0'' and returning 0. Similar to `mbrlen' there is also a non-reentrant function that computes the length of a multibyte character. It can be defined in terms of `mbtowc'. - Function: int mblen (const char *STRING, size_t SIZE) The `mblen' function with a non-null STRING argument returns the number of bytes that make up the multibyte character beginning at STRING, never examining more than SIZE bytes. (The idea is to supply for SIZE the number of bytes of data you have in hand.) The return value of `mblen' distinguishes three possibilities: the first SIZE bytes at STRING start with valid multibyte characters, they start with an invalid byte sequence or just part of a character, or STRING points to an empty string (a null character). For a valid multibyte character, `mblen' returns the number of bytes in that character (always at least `1' and never more than SIZE). For an invalid byte sequence, `mblen' returns -1. For an empty string, it returns 0. If the multibyte character code uses shift characters, then `mblen' maintains and updates a shift state as it scans. If you call `mblen' with a null pointer for STRING, that initializes the shift state to its standard initial value. It also returns a nonzero value if the multibyte character code in use actually has a shift state. Note: Shift State. The function `mblen' is declared in `stdlib.h'. automatically generated by info2www version 1.2.2.9 |