Wide character display column width subroutines
When characters are displayed or printed, the number of columns occupied by a character may differ. For example, a Kanji character (Japanese language) may occupy more than one column position. The number of display columns required by each character is part of the multicultural support locale database. The LC_CTYPE category defines the number of columns needed to display a character.
No standard multibyte display-column-width subroutines exist. For portability, convert multibyte codes to wide character codes and use the required wide character display-width subroutines. However, if the __max_disp_width macro (defined in the stdlib.h file) is set to 1 and a single-byte code set is in use, then the display-column widths of all characters (except tabs) in the code set are the same, and are equal to 1. In this case, the strlen (string) subroutine gives the display column width of the specified string, as shown in the following example:
#include <stdlib.h>
int display_column_width; /* number of display columns */
char *s; /* character string */
....
if((MB_CUR_MAX == 1) && (__max_disp_width == 1)){
display_column_width = strlen(s);
/* s is a string pointer */
}
The following subroutines find the display widths for wide character strings: