int wctob( wint_t c );
(since C95)Narrows a wide character c
if its multibyte character equivalent in the initial shift state is a single byte.
This is typically possible for the characters from the ASCII character set, since most multibyte encodings (such as UTF-8) use single bytes to encode those characters.
[edit] Parameters c - wide character to narrow [edit] Return valueEOF if c
does not represent a multibyte character with length 1 in initial shift state.
otherwise, the single-byte representation of c
as unsigned char converted to int
#include <locale.h> #include <wchar.h> #include <stdio.h> #include <assert.h> void try_narrowing(wchar_t c) { int cn = wctob(c); if(cn != EOF) printf("%#x narrowed to %#x\n", c, cn); else printf("%#x could not be narrowed\n", c); } int main(void) { char* utf_locale_present = setlocale(LC_ALL, "th_TH.utf8"); assert(utf_locale_present); puts("In Thai UTF-8 locale:"); try_narrowing(L'a'); try_narrowing(L'à¹'); char* tis_locale_present = setlocale(LC_ALL, "th_TH.tis620"); assert(tis_locale_present); puts("In Thai TIS-620 locale:"); try_narrowing(L'a'); try_narrowing(L'à¹'); }
Possible output:
In Thai UTF-8 locale: 0x61 narrowed to 0x61 0xe5b could not be narrowed In Thai TIS-620 locale: 0x61 narrowed to 0x61 0xe5b narrowed to 0xfb[edit] References
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4