From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/string%2Fmultibyte%2Fwctob.html | 54 +++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 devdocs/c/string%2Fmultibyte%2Fwctob.html (limited to 'devdocs/c/string%2Fmultibyte%2Fwctob.html') diff --git a/devdocs/c/string%2Fmultibyte%2Fwctob.html b/devdocs/c/string%2Fmultibyte%2Fwctob.html new file mode 100644 index 00000000..c942d365 --- /dev/null +++ b/devdocs/c/string%2Fmultibyte%2Fwctob.html @@ -0,0 +1,54 @@ +

wctob

Defined in header <wchar.h>
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.

+

Parameters

+ +
c - wide character to narrow

Return value

EOF 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

+

Example

#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

References

See also

+ +
+
(C95)
widens a single-byte narrow character to wide character, if possible
(function)
C++ documentation for wctob
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/string/multibyte/wctob +

+
-- cgit v1.2.3