[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: UTF-8 application
> No i want a C application.
I'm not sure what you really want, but here's something I put in a
configure script once.
You have to replace "eo.UTF-8" by something that gets you a UTF-8
locale on your machine. (Is there, or will there ever be, something
standard like "C.UTF-8"?)
Most libraries seem to fail this test, but recent versions of Bruno's
libutf8 pass.
Apparently with some versions of Solaris the last call to mbrtowc()
returns 2, and does so even if the third argument is changed to 1.
(The gibberish with int tb is because I didn't at the time know how to
escape [ ] in m4. Feel free to just declare char t[4] instead.)
Edmund
#include <stddef.h>
#include <stdlib.h>
#ifdef HAVE_WCHAR_H
#include <wchar.h>
#endif
#include <locale.h>
int main()
{
wchar_t wc = 123;
mbstate_t state;
const char *s = "\304\211";
int tb;
char *t = (char *)&tb;
setlocale(LC_ALL, "eo.UTF-8");
memset(&state, 0, sizeof(mbstate_t));
*(t+2) = 'x';
exit(!(mbrtowc(0, 0, 0, &state) == 0 &&
mbrtowc(&wc, s, 1, &state) == -2 && wc == 123 &&
mbrtowc(&wc, s+1, 2, &state) == 1 &&
wctomb(t, wc) == 2 && !memcmp(s, t, 2) && *(t+2) == 'x' &&
wcwidth(0) == 0 && wcwidth(wc) == 1 && wcwidth(127) == -1));
}
-
Linux-UTF8: i18n of Linux on all levels
Archive: http://mail.nl.linux.org/lists/