Revision: 794 http://svn.sourceforge.net/geany/?rev=794&view=rev Author: eht16 Date: 2006-09-06 10:31:53 -0700 (Wed, 06 Sep 2006)
Log Message: ----------- Convert tag names to UTF-8 before showing them in the sidebar.
Modified Paths: -------------- trunk/ChangeLog trunk/src/document.c trunk/src/utils.c trunk/src/utils.h
Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-09-06 16:09:08 UTC (rev 793) +++ trunk/ChangeLog 2006-09-06 17:31:53 UTC (rev 794) @@ -2,6 +2,8 @@
* src/callbacks.c, src/document.c, src/ui_utils.c, src/sci_cb.c: Added own implementation of an Undo stack (not yet working). + * src/utils.c, src/document.c: + Convert tag names to UTF-8 before showing them in the sidebar.
2006-09-05 Enrico Tröger enrico.troeger@uvena.de
Modified: trunk/src/document.c =================================================================== --- trunk/src/document.c 2006-09-06 16:09:08 UTC (rev 793) +++ trunk/src/document.c 2006-09-06 17:31:53 UTC (rev 794) @@ -511,7 +511,7 @@ } else { - gchar *converted_text = utils_convert_to_utf8_from_charset(data, size, forced_enc); + gchar *converted_text = utils_convert_to_utf8_from_charset(data, size, forced_enc, FALSE); if (converted_text == NULL) { msgwin_status_add(_("The file "%s" is not valid %s."), utf8_filename, forced_enc); @@ -542,7 +542,7 @@ bom = TRUE; if (enc[4] != '8') // the BOM indicated something else than UTF-8 { - gchar *converted_text = utils_convert_to_utf8_from_charset(data, size, enc); + gchar *converted_text = utils_convert_to_utf8_from_charset(data, size, enc, FALSE); if (converted_text == NULL) { g_free(enc);
Modified: trunk/src/utils.c =================================================================== --- trunk/src/utils.c 2006-09-06 16:09:08 UTC (rev 793) +++ trunk/src/utils.c 2006-09-06 17:31:53 UTC (rev 794) @@ -201,6 +201,8 @@ TMTag *tag; guint i; GeanySymbol *symbol; + gboolean doc_is_utf8 = FALSE; + gchar *utf8_name;
if (tag_names) { @@ -214,18 +216,24 @@ tag_names = NULL; }
+ // do this comparison only once + if (utils_strcmp(doc_list[idx].encoding, "UTF-8")) doc_is_utf8 = TRUE; + for (i = 0; i < (doc_list[idx].tm_file)->tags_array->len; ++i) { tag = TM_TAG((doc_list[idx].tm_file)->tags_array->pdata[i]); if (tag == NULL) return NULL; - //geany_debug("%s: %d", doc_list[idx].file_name, tag->type); + if (tag->type & tag_types) { + if (! doc_is_utf8) utf8_name = utils_convert_to_utf8_from_charset(tag->name, -1, + doc_list[idx].encoding, TRUE); + else utf8_name = tag->name; if ((tag->atts.entry.scope != NULL) && isalpha(tag->atts.entry.scope[0])) { symbol = g_new0(GeanySymbol, 1); - symbol->str = g_strdup_printf("%s::%s [%ld]", tag->atts.entry.scope, tag->name, tag->atts.entry.line); + symbol->str = g_strdup_printf("%s::%s [%ld]", tag->atts.entry.scope, utf8_name, tag->atts.entry.line); symbol->type = tag->type; symbol->line = tag->atts.entry.line; tag_names = g_list_prepend(tag_names, symbol); @@ -233,11 +241,12 @@ else { symbol = g_new0(GeanySymbol, 1); - symbol->str = g_strdup_printf("%s [%ld]", tag->name, tag->atts.entry.line); + symbol->str = g_strdup_printf("%s [%ld]", utf8_name, tag->atts.entry.line); symbol->type = tag->type; symbol->line = tag->atts.entry.line; tag_names = g_list_prepend(tag_names, symbol); } + if (! doc_is_utf8) g_free(utf8_name); } } tag_names = g_list_sort(tag_names, (GCompareFunc) utils_compare_symbol); @@ -335,7 +344,10 @@ }
-gchar *utils_convert_to_utf8_from_charset(const gchar *buffer, gsize size, const gchar *charset) +/* Converts a string from the given charset to UTF-8. + * If fast is set, no further checks are performed. */ +gchar *utils_convert_to_utf8_from_charset(const gchar *buffer, gsize size, const gchar *charset, + gboolean fast) { gchar *utf8_content = NULL; GError *conv_error = NULL; @@ -346,10 +358,15 @@ g_return_val_if_fail(charset != NULL, NULL);
converted_contents = g_convert(buffer, size, "UTF-8", charset, NULL, - &bytes_written, &conv_error); + &bytes_written, &conv_error);
- if (conv_error != NULL || ! g_utf8_validate(converted_contents, bytes_written, NULL)) + if (fast) { + utf8_content = converted_contents; + if (conv_error != NULL) g_error_free(conv_error); + } + else if (conv_error != NULL || ! g_utf8_validate(converted_contents, bytes_written, NULL)) + { if (conv_error != NULL) { geany_debug("Couldn't convert from %s to UTF-8 (%s).", charset, conv_error->message); @@ -395,7 +412,7 @@ charset = encodings[i].charset;
geany_debug("Trying to convert %d bytes of data from %s into UTF-8.", size, charset); - utf8_content = utils_convert_to_utf8_from_charset(buffer, size, charset); + utf8_content = utils_convert_to_utf8_from_charset(buffer, size, charset, FALSE);
if (utf8_content != NULL) {
Modified: trunk/src/utils.h =================================================================== --- trunk/src/utils.h 2006-09-06 16:09:08 UTC (rev 793) +++ trunk/src/utils.h 2006-09-06 17:31:53 UTC (rev 794) @@ -46,7 +46,10 @@
gchar *utils_convert_to_utf8(const gchar *buffer, gsize size, gchar **used_encoding);
-gchar *utils_convert_to_utf8_from_charset(const gchar *buffer, gsize size, const gchar *charset); +/* Converts a string from the given charset to UTF-8. + * If fast is set, no further checks are performed. */ +gchar *utils_convert_to_utf8_from_charset(const gchar *buffer, gsize size, const gchar *charset, + gboolean fast);
/** * (stolen from anjuta and modified)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.