/* * Module for handling utf8 just like any other charset. */ #include #include #include #include static int utf8_uni2char(unsigned char ch, unsigned char cl, unsigned char *out, int boundlen, int *outlen) { int n; int ret = 0; if ( (n = utf8_wctomb(out, ch<<8 | cl, boundlen)) == -1) { *out = '?'; n = 1; ret = -1; } *outlen = n; return ret; } static void utf8_char2uni(unsigned char *rawstring, int *offset, unsigned char *uni1, unsigned char *uni2) { __u16 x; int n; /* "10" is just a random value */ if ( (n = utf8_mbtowc(&x, rawstring, 10)) == -1) { x = '?'; n = 1; } *uni2 = (x & 0xff00) >> 8; *uni1 = (x & 0x00ff); *offset = n; } /* Note: no 2upper/2lower conversion, just byte parsing */ static int utf8_char2lower(const unsigned char *rawstring, int *offset, unsigned char *low, int outputlen) { __u16 x; int n; /* "10" is just a random value */ if ( (n = utf8_mbtowc(&x, rawstring, 10)) == -1) { return -1; } *offset = n; memcpy(low, rawstring, n); return n; } static struct nls_table table = { "utf8", utf8_uni2char, utf8_char2uni, utf8_char2lower, utf8_char2lower, THIS_MODULE, }; static int __init init_nls_utf8(void) { return register_nls(&table); } static void __exit exit_nls_utf8(void) { unregister_nls(&table); } module_init(init_nls_utf8) module_exit(exit_nls_utf8)