wcwidth(), wcwidth_l()

number of column positions of a wide-character code 

Function


SYNOPSIS

#include <wchar.h>

int wcwidth(wchar_t wc);

int wcwidth_l(wchar_t wc, locale_t locale);


DESCRIPTION

The wcwidth() and wcwidth_l() functions determines the number of column positions required to display the wide character wc.

wcwidth_l() behaves in the same way as wcwidth() without the _l suffix, but uses the specified locale rather than the global or per-thread locale. A locale_t is returned by newlocale().


PARAMETERS

wc 

The wide character to scan.

locale 

Is a locale_t perhaps returned by newlocale() or LC_GLOBAL_LOCALE or 0 for the current thread locale set with uselocale().


RETURN VALUES

The wcwidth() and wcwidth_l() functions return 0 if the wc argument is a null wide character (L"\0"), -1 if wc is not printable, otherwise it returns the number of column positions the character occupies.


EXAMPLES

This code fragment reads text from standard input and breaks lines that are more than 20 column positions wide, similar to the fold utility:

    wint_t ch;
    int column, w;

    column = 0;
    while ((ch = getwchar()) != WEOF) {
        w = wcwidth(ch);
        if (w > 0 && column + w >= 20) {
            putwchar(L'\n');
            column = 0;
        }
        putwchar(ch);
        if (ch == L'\n') {
            column = 0;
        }
        else if (w > 0) {
            column += w;
        }
    }

CONFORMANCE

wcwidth() conforms to IEEE Std 1003.1-2001 'POSIX.1'. wcwidth_l() conforms to IEEE Std 1003.1-2008 'POSIX.1'.


MULTITHREAD SAFETY LEVEL

MT-Safe, with exceptions.

The function wcwidth() is MT-Safe as long as no thread calls setlocale() while this function is executing.

The function wcwidth_l() is MT-Safe as long as no thread calls freelocale() on locale while this function is executing.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
iswprint(), newlocale(), setlocale(), wcswidth(), wcswidth_l()


PTC MKS Toolkit 10.4 Documentation Build 39.