Changeset 3461 for trunk/jons-gtk2-gui
- Timestamp:
- 04/27/03 03:35:26 (6 years ago)
- Files:
-
- 1 modified
-
trunk/jons-gtk2-gui/src/utilities.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/jons-gtk2-gui/src/utilities.cpp
r3432 r3461 29 29 { 30 30 if (input_text == NULL) 31 return NULL;32 33 if (input_text[0] == 0)34 return g_strdup(input_text);35 36 size_t len = strlen(input_text);37 if (!g_utf8_validate(input_text, len, NULL)) {38 gsize b_in, b_out;31 return NULL; 32 33 if (input_text[0] == 0) 34 return g_strdup(input_text); 35 36 size_t len = strlen(input_text); 37 if (!g_utf8_validate(input_text, len, NULL)) { 38 gsize b_in, b_out; 39 39 if (input_enc != NULL && *input_enc != 0 && 40 strcasecmp(input_enc, "UTF-8") != 0) 41 return g_convert(input_text, len, "UTF-8", input_enc, &b_in, &b_out, 42 NULL); 40 strcasecmp(input_enc, "UTF-8") != 0) 41 return g_convert(input_text, len, "UTF-8", input_enc, &b_in, &b_out, NULL); 43 42 else { 44 43 const char *cs; 45 44 if (g_get_charset(&cs) || strcmp(cs, "ANSI_X3.4-1968") == 0) 46 // locale is either already utf8 or ASCII so conversion won't help45 // locale is either already utf8 or ASCII so conversion won't help 47 46 // - we use fallback character set - iso8859-1 48 47 return g_convert(input_text, len, "UTF-8", "ISO8859-1", &b_in, &b_out, 49 NULL);48 NULL); 50 49 else 51 50 return g_convert(input_text, len, "UTF-8", cs, &b_in, &b_out, NULL); 52 51 } 53 52 } 54 55 53 return g_strdup(input_text); 56 54 } … … 60 58 { 61 59 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);60 return NULL; 61 62 if (input_text[0] == 0) 63 return g_strdup(input_text); 64 65 size_t len = strlen(input_text); 68 66 69 gsize b_in, b_out;70 if (output_enc != NULL && *output_enc != 0 && 67 gsize b_in, b_out; 68 if (output_enc != NULL && *output_enc != 0 && 71 69 strcasecmp(output_enc, "UTF-8") != 0) 72 return g_convert(input_text, len, 73 output_enc, "UTF-8", &b_in, &b_out, NULL); 70 return g_convert(input_text, len, output_enc, "UTF-8", &b_in, &b_out, NULL); 74 71 else { 75 72 const char *cs; 76 73 if (g_get_charset(&cs)) 77 // locale is already utf8 so conversion won't help - we use78 // fallback character set - iso8859-179 return g_convert(input_text, len, 80 "ISO8859-1", "UTF-8", &b_in, &b_out,NULL);74 // locale is already utf8 so conversion won't help - we use 75 // fallback character set - iso8859-1 76 return g_convert(input_text, len, "ISO8859-1", "UTF-8", &b_in, &b_out, 77 NULL); 81 78 else 82 return g_convert(input_text, len, 83 cs, "UTF-8", &b_in, &b_out, NULL); 79 return g_convert(input_text, len, cs, "UTF-8", &b_in, &b_out, NULL); 84 80 } 85 86 81 return g_strdup(input_text); 87 82 } … … 125 120 { 126 121 GtkTextBuffer *tb = gtk_text_view_get_buffer(GTK_TEXT_VIEW(w)); 127 GtkTextIter b, e; 128 gtk_text_buffer_get_start_iter(tb, &b); 129 gtk_text_buffer_get_end_iter(tb, &e); 130 122 GtkTextIter b, e; 123 gtk_text_buffer_get_start_iter(tb, &b); 124 gtk_text_buffer_get_end_iter(tb, &e); 131 125 gchar *txt = gtk_text_buffer_get_text(tb, &b, &e, FALSE); 132 126 if (txt != NULL && *txt != 0) { … … 144 138 gtk_button_box_set_layout(GTK_BUTTON_BOX(h_box), layout_style); 145 139 gtk_box_set_spacing(GTK_BOX(h_box), spacing); 146 147 return h_box;140 141 return h_box; 148 142 } 149 143 150 144 encoding encodings[] = { 151 {"Unicode", "UTF-8"},152 {"Arabic", "ISO8859-6"},153 {"Arabic", "CP1256"},154 {"Baltic", "ISO8859-13"},155 {"Baltic", "CP1257"},156 {"Central European", "ISO8859-2"},157 {"Central European", "CP1250"},158 {"Chinese", "GBK"},159 {"Chinese Traditional", "Big5"},160 {"Cyrillic", "ISO8859-5"},161 {"Cyrillic", "KOI8-R"},162 {"Cyrillic", "CP1251"},163 {"Esperanto", "ISO8859-3"},164 {"Greek", "ISO8859-7"},165 {"Greek", "CP1253"},166 {"Hebrew", "ISO8859-8-I"},167 {"Hebrew", "CP1255"},168 {"Japanese", "Shift-JIS"},169 {"Japanese", "JIS7"},170 {"Japanese", "eucJP"},171 {"Korean", "eucKR"},172 {"Western European", "ISO8859-1"},173 {"Western European", "ISO8859-15"},174 {"Western European", "CP1252"},175 {"Tamil", "TSCII"},176 {"Thai", "TIS-620"},177 {"Turkish", "ISO8859-9"},178 {"Turkish", "CP1254"},179 {"Ukrainian", "KOI8-U"},180 {0, 0}}; // end marker145 {"Unicode", "UTF-8"}, 146 {"Arabic", "ISO8859-6"}, 147 {"Arabic", "CP1256"}, 148 {"Baltic", "ISO8859-13"}, 149 {"Baltic", "CP1257"}, 150 {"Central European", "ISO8859-2"}, 151 {"Central European", "CP1250"}, 152 {"Chinese", "GBK"}, 153 {"Chinese Traditional", "Big5"}, 154 {"Cyrillic", "ISO8859-5"}, 155 {"Cyrillic", "KOI8-R"}, 156 {"Cyrillic", "CP1251"}, 157 {"Esperanto", "ISO8859-3"}, 158 {"Greek", "ISO8859-7"}, 159 {"Greek", "CP1253"}, 160 {"Hebrew", "ISO8859-8-I"}, 161 {"Hebrew", "CP1255"}, 162 {"Japanese", "Shift-JIS"}, 163 {"Japanese", "JIS7"}, 164 {"Japanese", "eucJP"}, 165 {"Korean", "eucKR"}, 166 {"Western European", "ISO8859-1"}, 167 {"Western European", "ISO8859-15"}, 168 {"Western European", "CP1252"}, 169 {"Tamil", "TSCII"}, 170 {"Thai", "TIS-620"}, 171 {"Turkish", "ISO8859-9"}, 172 {"Turkish", "CP1254"}, 173 {"Ukrainian", "KOI8-U"}, 174 {0, 0}}; // end marker
