[easytag] Improve unknown encoding case when reading ID3v2
- From: David King <davidk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [easytag] Improve unknown encoding case when reading ID3v2
- Date: Fri, 27 Mar 2015 17:56:42 +0000 (UTC)
commit b998f5b09ae7e1e664b3598fa6b2fa1ad2039bdc
Author: David King <amigadave amigadave com>
Date: Fri Mar 27 18:53:46 2015 +0100
Improve unknown encoding case when reading ID3v2
Drop use of the internal convert_to_utf8() function, and instead place
the conversion logic directly in the ID3 code.
src/charset.c | 35 -----------------------------------
src/charset.h | 3 ---
src/scan_dialog.c | 8 --------
src/tags/id3_tag.c | 20 +++++++++++++++++++-
4 files changed, 19 insertions(+), 47 deletions(-)
---
diff --git a/src/charset.c b/src/charset.c
index d08c19e..40b8f59 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -429,41 +429,6 @@ convert_string_1 (const gchar *string, gssize length, const gchar *from_codeset,
return output;
}
-
-/*
- * Conversion with UTF-8 for Ogg Vorbis and FLAC tags (current_charset <===> UTF-8)
- */
-gchar *convert_to_utf8 (const gchar *string)
-{
- gchar *output;
- GError *error = NULL;
-
- g_return_val_if_fail (string != NULL, NULL);
-
- output = g_locale_to_utf8(string, -1, NULL, NULL, &error);
-
- if (output == NULL)
- {
- const gchar *usercharset;
- gchar *escaped_str = g_strescape(string, NULL);
- g_get_charset(&usercharset);
- Log_Print(LOG_ERROR,"convert_to_utf8(): Failed conversion from charset '%s'. "
- "String '%s'. Errcode %d (%s).",
- usercharset, escaped_str, error->code, error->message);
- g_free(escaped_str);
-
- if (g_utf8_validate(string, -1, NULL))
- Log_Print(LOG_ERROR,"convert_to_utf8(): String was valid UTF-8.");
- else
- Log_Print(LOG_ERROR,"convert_to_utf8(): String was INVALID UTF-8.");
-
- g_error_free(error);
- return g_strdup(string);
- }
-
- return output;
-}
-
/*
* Convert a string from the filename system encoding to UTF-8.
* - conversion OK : returns the UTF-8 string (new allocated)
diff --git a/src/charset.h b/src/charset.h
index 128de1d..decce1e 100644
--- a/src/charset.h
+++ b/src/charset.h
@@ -30,9 +30,6 @@ const gchar *get_locale (void);
gchar *convert_string (const gchar *string, const gchar *from_codeset, const gchar *to_codeset, const
gboolean display_error);
gchar *convert_string_1 (const gchar *string, gssize length, const gchar *from_codeset, const gchar
*to_codeset, const gboolean display_error);
-/* Used for Ogg Vorbis and FLAC tags */
-gchar *convert_to_utf8 (const gchar *string);
-
gchar *filename_to_display (const gchar *string);
gchar *filename_from_display (const gchar *string);
diff --git a/src/scan_dialog.c b/src/scan_dialog.c
index 620401b..e3ee611 100644
--- a/src/scan_dialog.c
+++ b/src/scan_dialog.c
@@ -1669,10 +1669,6 @@ Mask_Editor_List_Add (EtScanDialog *self)
{
while(Scan_Masks[i])
{
- /*if (!g_utf8_validate(Scan_Masks[i], -1, NULL))
- temp = convert_to_utf8(Scan_Masks[i]);
- else
- temp = g_strdup(Scan_Masks[i]);*/
temp = Try_To_Validate_Utf8_String(Scan_Masks[i]);
gtk_list_store_insert_with_values (GTK_LIST_STORE (treemodel),
@@ -1685,10 +1681,6 @@ Mask_Editor_List_Add (EtScanDialog *self)
{
while(Rename_File_Masks[i])
{
- /*if (!g_utf8_validate(Rename_File_Masks[i], -1, NULL))
- temp = convert_to_utf8(Rename_File_Masks[i]);
- else
- temp = g_strdup(Rename_File_Masks[i]);*/
temp = Try_To_Validate_Utf8_String(Rename_File_Masks[i]);
gtk_list_store_insert_with_values (GTK_LIST_STORE (treemodel),
diff --git a/src/tags/id3_tag.c b/src/tags/id3_tag.c
index bd48e3a..76d3c98 100644
--- a/src/tags/id3_tag.c
+++ b/src/tags/id3_tag.c
@@ -1047,7 +1047,25 @@ gchar *Id3tag_Get_Field (const ID3Frame *id3_frame, ID3_FieldID id3_fieldid)
default:
string = g_malloc0 (4 * ID3V2_MAX_STRING_LEN + 1);
num_chars = ID3Field_GetASCII_1(id3_field,string,ID3V2_MAX_STRING_LEN,0);
- string1 = convert_to_utf8(string);
+
+ if (g_utf8_validate (string, -1, NULL))
+ {
+ string1 = g_strdup (string);
+ }
+ else
+ {
+ GError *error = NULL;
+
+ string1 = g_locale_to_utf8 (string, -1, NULL, NULL,
+ &error);
+
+ if (string1 == NULL)
+ {
+ g_debug ("Error converting string from locale to UTF-8 encoding: %s",
+ error->message);
+ g_error_free (error);
+ }
+ }
break;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]