Created
March 31, 2011 21:13
-
-
Save bnoordhuis/897271 to your computer and use it in GitHub Desktop.
utf7.c
This file contains hidden or 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 <stdlib.h> | |
#include <string.h> | |
#include <assert.h> | |
#include <errno.h> | |
#include "iconv.h" | |
int main(void) { | |
size_t inbytesleft, outbytesleft; | |
char *inbuf, *outbuf, data[32]; | |
iconv_t iv; | |
int rv; | |
iv = iconv_open("UTF-7", "UTF-8"); | |
assert(iv != (iconv_t) -1); | |
inbuf = "\xC3\xA7"; // "ç" | |
inbytesleft = 2; | |
outbuf = data; | |
outbytesleft = sizeof data; | |
errno = 0; | |
rv = iconv(iv, &inbuf, &inbytesleft, &outbuf, &outbytesleft); | |
assert(errno == 0); | |
assert(inbytesleft == 0); | |
data[sizeof data - outbytesleft] = '\0'; | |
printf("Converted to '%s'\n", data); | |
iconv_close(iv); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment