Created
March 22, 2026 05:37
-
-
Save santhoshtr/6d8a45729da77dda27187963913bf58d to your computer and use it in GitHub Desktop.
wc-width-test.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #define _XOPEN_SOURCE | |
| #include <stdio.h> | |
| #include <wchar.h> | |
| #include <locale.h> | |
| int main(void) { | |
| setlocale(LC_ALL, ""); | |
| struct { | |
| wchar_t ch; | |
| const char *name; | |
| } letters[] = { | |
| /* Malayalam - width 1 */ | |
| { L'അ', "Malayalam: അ (a)" }, | |
| { L'ആ', "Malayalam: ആ (aa)" }, | |
| { L'ക', "Malayalam: ക (ka)" }, | |
| { L'ഴ', "Malayalam: ഴ (zha)" }, | |
| { L'ൾ', "Malayalam: ൾ (chillu ll)" }, | |
| /* CJK Unified Ideographs - width 2 */ | |
| { L'中', "Chinese: 中 (zhong, middle)" }, | |
| { L'日', "Japanese: 日 (hi, sun/day)" }, | |
| { L'한', "Korean: 한 (han)" }, | |
| { L'語', "CJK: 語 (language)" }, | |
| { L'火', "CJK: 火 (fire)" }, | |
| /* CJK Extension B (beyond BMP) - width 2 */ | |
| { L'𠀀', "CJK Ext-B: 𠀀 (U+20000)" }, | |
| { L'𡀀', "CJK Ext-B: 𡀀 (U+21000)" }, | |
| /* Fullwidth Latin - width 2 */ | |
| { L'A', "Fullwidth: A (U+FF21)" }, | |
| { L'!', "Fullwidth: ! (U+FF01)" }, | |
| /* Emoji / symbols - width 2 */ | |
| { L'★', "Symbol: ★ BLACK STAR (U+2605)" }, | |
| { L'→', "Symbol: → RIGHT ARROW (U+2192)" }, | |
| /* Zero-width / combining - width 0 */ | |
| { L'\u200C', "ZWNJ (U+200C)" }, | |
| { L'\u200D', "ZWJ (U+200D)" }, | |
| { L'\u0300', "Combining grave accent (U+0300)" }, | |
| { L'\u0D4D', "Malayalam virama ് (U+0D4D)" }, | |
| /* Latin & other scripts - width 1 */ | |
| { L'é', "Latin: é (U+00E9)" }, | |
| { L'ñ', "Latin: ñ (U+00F1)" }, | |
| { L'Ж', "Cyrillic: Ж (zhe)" }, | |
| { L'α', "Greek: α (alpha)" }, | |
| { L'ש', "Hebrew: ש (shin)" }, | |
| { L'ع', "Arabic: ع (ayn)" }, | |
| { L'ก', "Thai: ก (ko kai)" }, | |
| { L'ሀ', "Ethiopic: ሀ (ha)" }, | |
| { L'\0', NULL } | |
| }; | |
| printf("%-38s %-10s %s\n", "Character", "U+Code", "wcwidth"); | |
| printf("%-38s %-10s %s\n", "---------", "------", "-------"); | |
| for (int i = 0; letters[i].ch != L'\0'; i++) { | |
| int w = wcwidth(letters[i].ch); | |
| printf("%-38s U+%06X %d\n", | |
| letters[i].name, | |
| (unsigned int)letters[i].ch, | |
| w); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment