Name

wcwidth - determine columns needed for a wide character

Library

libc.lib

Synopsis

  #include <wchar.h>
  int wcwidth (wchar_t wc);

Return values

The wcwidth function returns 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.

Detailed description

The wcwidth function determines the number of column positions required to display the wide character wc.

The behavior of the wcwdith is affected by LC_CTYPE category of the current locale.


Examples

#include <wchar.h>
/* Illustrates how to use wcwidth API */
int example_wcwidth()
{  
 /* wide character for which width has to be determined */
 wchar_t wc = L’a’;
 int retval;
 /* determine the width of wc */
 retval = wcwidth(wc);
 /* return the determined width */
 return retval;
}

         


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’ \en’);
                column = 0;
        }
        putwchar(ch);
        if (ch == L’ \en’)
                column = 0;
        else if (w > 0)
                column += w;
}

         


Limitations

The current implementation of wcwidth is dependent on the locale support of SYMBIAN. It doesn’t work for the locales which the SYMBIAN doesn’t support.

See also

iswprint, wcswidth

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top