| | 53 | } |
| | 54 | |
| | 55 | return g_strdup(input_text); |
| | 56 | } |
| | 57 | |
| | 58 | char * |
| | 59 | convert_from_utf8(const char *input_text, const char *output_enc) |
| | 60 | { |
| | 61 | if (input_text == NULL) |
| | 62 | return NULL; |
| | 63 | |
| | 64 | if (input_text[0] == 0) |
| | 65 | return g_strdup(input_text); |
| | 66 | |
| | 67 | size_t len = strlen(input_text); |
| | 68 | |
| | 69 | gsize b_in, b_out; |
| | 70 | if (output_enc != NULL && *output_enc != 0 && |
| | 71 | strcasecmp(output_enc, "UTF-8") != 0) |
| | 72 | return g_convert(input_text, len, |
| | 73 | output_enc, "UTF-8", &b_in, &b_out, NULL); |
| | 74 | else { |
| | 75 | const char *cs; |
| | 76 | if (g_get_charset(&cs)) |
| | 77 | // locale is already utf8 so conversion won't help - we use |
| | 78 | // fallback character set - iso8859-1 |
| | 79 | return g_convert(input_text, len, |
| | 80 | "ISO8859-1", "UTF-8", &b_in, &b_out, NULL); |
| | 81 | else |
| | 82 | return g_convert(input_text, len, |
| | 83 | cs, "UTF-8", &b_in, &b_out, NULL); |