From 616a7d3f8ab4856469b29f34328ea07161911676 Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Mon, 29 Dec 2008 20:43:30 +0100 Subject: support for alternative names of code sets --- TODO | 4 ++-- iconv.c | 16 +++++++++++++--- test.c | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/TODO b/TODO index 4ba3307..0aadebf 100644 --- a/TODO +++ b/TODO @@ -1,2 +1,2 @@ -Support multiple names on same codesets. i.e UTF8 = UTF-8 - +Support for 3 and 4 char utf8 (full utf-8 support) +Support for EUC-JP diff --git a/iconv.c b/iconv.c index 6fa63a7..b5a7f3d 100644 --- a/iconv.c +++ b/iconv.c @@ -43,12 +43,12 @@ struct converter supported_codesets[] = { .encode = &encode_ascii, }, { .code = UTF_8, - .name = "UTF-8", + .name = "UTF-8" "\0" "UTF8" "\0", .decode = &decode_utf_8, .encode = &encode_utf_8, }, { .code = ISO_8859_1, - .name = "ISO-8859-1", + .name = "ISO-8859-1" "\0" "ISO8859-1" "\0", .decode = &decode_iso_8859_1, .encode = &encode_iso_8859_1 }, { @@ -151,6 +151,16 @@ static void toupperstr(char *p) } } +static int is_codeset(const char *str, const char *list) +{ + while (*list) { + if (strcmp(str, list) == 0) + return 1; + list += strlen(list) + 1; + } + return 0; +} + static int find_converter(const char *str) { int i; @@ -159,7 +169,7 @@ static int find_converter(const char *str) buf[15] = '\0'; toupperstr(buf); for (i = 0; supported_codesets[i].code != -1; i++) { - if (strcmp(buf, supported_codesets[i].name) == 0) + if (is_codeset(buf, supported_codesets[i].name)) return i; } return -1; diff --git a/test.c b/test.c index 4638a4a..5d22d35 100644 --- a/test.c +++ b/test.c @@ -55,7 +55,7 @@ void convert_args(char *from, char *to, int argc, char **argv) int main(int argc, char **argv) { - char *codesets[] = { "ASCII", "ISO-8859-1", "UTF-8", "invalid", NULL }; + char *codesets[] = { "ASCII", "ISO-8859-1", "iso8859-1", "UTF-8", "utf8", "invalid", NULL }; char **from, **to; for (from = codesets; *from; from++) -- cgit v1.2.3