-
-
Save devinacker/cd09eb2ab4608b3d90f1 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 <glib.h> | |
#include <stdio.h> | |
int main() { | |
// test a string with non-ASCII code points below U+0100 | |
const unsigned char test1[] = "http://google.com/?q=tést"; | |
// test a string with code points above U+0100 | |
const unsigned char test2[] = "http://google.com/?q=テスト"; | |
GError *err = NULL; | |
char *loc; | |
if (loc = g_locale_from_utf8(test1, -1, NULL, NULL, &err)) { | |
printf("test1: translated string is %s\n", loc); | |
g_free(loc); | |
} else if (err) { | |
printf("test1 error: %s\n", err->message); | |
g_error_free(err); | |
err = NULL; | |
} | |
printf("test2: UTF-8 byte sequence is: "); | |
for (int i = 0; test2[i]; i++) | |
printf("%02X ", test2[i]); | |
printf("\n"); | |
if (loc = g_locale_from_utf8(test2, -1, NULL, NULL, &err)) { | |
printf("test2: translated string is %s\n", loc); | |
g_free(loc); | |
} else if (err) { | |
printf("test2 error: %s\n", err->message); | |
g_error_free(err); | |
err = NULL; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment