If you want to avoid the conversion at any cost, you would have to write a bunch of different routines:
static void handle_iso_8859_1(const char *);
static void handle_iso_8859_15(const char *);
static void handle_utf_8(const char *);
static void handle_string(const char *s, const char *encoding) {
if (strcmp(encoding, "ISO-8859-1") == 0) {
handle_iso_8859_1(s);
} else if (strcmp(encoding, "ISO-8859-15") == 0) {
handle_iso_8859_15(s);
} else if (strcmp(encoding, "UTF-8") == 0) {
handle_utf_8(s);
} else {
error("unknown encoding: %s", encoding);
}
}
Why do you want to avoid the conversion in the first place? Is it too costly? Is it really too costly? Converting from ISO-8859-1 to UTF-8 is quite cheap and easy to do. Well, maybe you need one extra memory allocation and some copying of bytes. But is that really worth writing mostly the same code three (or more) times?