ISO charsets: lookup_charset The enumerated type [[ISO_charset]] contains the list of all known charsets. The function [[lookup_charset]] tries to map a string to one of them. The comparison is done case insensitively and while ignoring everything that is not a letter or digit. Therefore, [["ISO-8859_1"]] and [["ISO8859.1"]] and [["ISO.8859/1"]] will all be mapped to [[ISO8859_1]]. <<*>>= #include #include EXPORT typedef enum { US_ASCII, ISO8859_1, ISO8859_2, ISO8859_3, ISO8859_4, ISO8859_5, ISO8859_6, ISO8859_7, ISO8859_8, ISO8859_9, } ISO_charset; EXPORT char *ISO_charset_repr[] = { "US-ASCII", "ISO8859-1", "ISO8859-2", "ISO8859-3", "ISO8859-4", "ISO8859-5", "ISO8859-6", "ISO8859-7", "ISO8859-8", "ISO8859-9", }; #define charset2str(c) (ISO_charset_repr[c]) EXPORTDEF(charset2str(c)) EXPORT ISO_charset str2charset(char *s) { char t[256]; int i; for (i = 0; *s && i < sizeof(t) - 1; s++) if (isalnum(*s)) t[i++] = *s; t[i] = '\0'; if (case_eq(t, "USASCII")) return US_ASCII; if (case_eq(t, "ISO88591")) return ISO8859_1; if (case_eq(t, "ISO88592")) return ISO8859_2; if (case_eq(t, "ISO88593")) return ISO8859_3; if (case_eq(t, "ISO88594")) return ISO8859_4; if (case_eq(t, "ISO88595")) return ISO8859_5; if (case_eq(t, "ISO88596")) return ISO8859_6; if (case_eq(t, "ISO88597")) return ISO8859_7; if (case_eq(t, "ISO88598")) return ISO8859_8; if (case_eq(t, "ISO88599")) return ISO8859_9; return US_ASCII; }