Created
February 25, 2009 03:57
-
-
Save k0001/69988 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
#include <stdlib.h> | |
#include <locale.h> | |
#include <wctype.h> | |
#include <langinfo.h> | |
int main(int argc, char **argv) | |
{ | |
if (!setlocale(LC_ALL, "")) { | |
fprintf(stderr, "Can't set the specified locale! " \ | |
"Check your LANG and LC_* environment variables\n"); | |
return 1; | |
} | |
int i = 0 , j = 0, k = 0; | |
wchar_t *s = L"H€Łło 3rð. WØrŁÐ!\xfb46"; | |
wint_t c = 0; | |
unsigned char enc_bytes[4]; | |
char *wcprops[] = { | |
"alnum", "alpha", "cntrl", "digit", | |
"graph", "lower", "print", "punct", | |
"space", "upper", "xdigit", NULL | |
}; | |
size_t slen = wcslen(s); | |
printf("String: %ls\n", s); | |
printf("String Length: %d\n", slen); | |
for (i = 0; i < slen; ++i) { | |
c = s[i]; | |
printf("%02d: %lc ~ U+%04x | %lc %lc | ", i + 1, c, c, towlower(c), towupper(c)); | |
for (j = 0; wcprops[j] != NULL; ++j) { | |
if (iswctype(c, wctype(wcprops[j]))) | |
printf("+"); | |
else | |
printf("-"); | |
printf("%s ", wcprops[j]); | |
} | |
printf("| %s bytes: ", nl_langinfo(CODESET)); | |
for (j = 0, k = wcrtomb(enc_bytes, c, NULL); j < k; ++j) | |
printf("%02x ", enc_bytes[j]); | |
printf("\n"); | |
} | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment