]>
diplodocus.org Git - nmh/blob - test/getcwidth.c
2 * getcwidth - Get the OS's idea of the width of a combining character
4 * This code is Copyright (c) 2012, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * complete copyright information.
18 #ifdef MULTIBYTE_SUPPORT
24 main(int argc
, char *argv
[])
31 * This is the UTF-8 for "n" + U+0308 (Combining Diaeresis)
34 unsigned char string
[] = "n\xcc\x88";
36 setlocale(LC_ALL
, "");
39 fprintf(stderr
, "Usage: %s\n", argv
[0]);
40 fprintf(stderr
, "Returns the column width of a UTF-8 "
41 "multibyte character\n");
45 #ifndef MULTIBYTE_SUPPORT
46 fprintf(stderr
, "Nmh was not configured with multibyte support\n");
50 * It's not clear to me that we can just call mbtowc() with a
51 * combining character; just to be safe, feed it in a base
55 mbtowc(NULL
, NULL
, 0);
57 charlen
= mbtowc(&c
, (char *) string
, strlen((char *) string
));
60 fprintf(stderr
, "We expected a beginning character length "
61 "of 1, got %d instead\n", charlen
);
65 p
= (char *) (string
+ charlen
);
67 charlen
= mbtowc(&c
, p
, strlen(p
));
70 fprintf(stderr
, "We expected a multibyte character length "
71 "of 2, got %d instead\n", charlen
);
72 fprintf(stderr
, "Are you using a UTF-8 locale?\n");
76 printf("%d\n", wcwidth(c
));
79 #endif /* MULTIBYTE_SUPPORT */