Вопрос

Why does here wcwidth return "-1" (not a printable wide character) width "Ԥ" (0x0524)?

#include <stdio.h>
#include <wchar.h>
#include <locale.h>

int wcwidth(wchar_t wc);

int main()
{
    setlocale(LC_CTYPE, "");

    wchar_t wc1 = L'合'; // 0x5408
    int width1 = wcwidth(wc1);
    printf("%lc - print width: %i\n", wc1, width1);

    wchar_t wc2 = L'Ԥ'; // 0x0524
    int width2 = wcwidth(wc2);
    printf("%lc - print width: %i\n", wc2, width2);

    return 0;
}

Output:

合 - print width: 2
Ԥ - print width: -1
Это было полезно?

Решение

Most likely U+0524 was not a valid character when your libc character database was created. It was added in Unicode 5.2. Your font may include the character already, but wcwidth does not look at which font is used.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top