Commit 3bdb4f94 authored by Paolo Bacchilega's avatar Paolo Bacchilega

exiv2: remove the charset= prefix from strings

Fixes #137
parent a658a8ce
......@@ -273,14 +273,10 @@ create_metadata (const char *key,
else
formatted_value_utf8 = g_locale_to_utf8 (formatted_value, -1, NULL, NULL, NULL);
}
else if (_g_utf8_has_prefix (formatted_value_utf8, "lang=")) {
const char *after_space;
char *formatted_clean;
after_space = _g_utf8_after_ascii_space (formatted_value_utf8);
formatted_clean = g_strdup (after_space);
else {
char *tmp = _g_utf8_remove_string_properties (formatted_value_utf8);
g_free (formatted_value_utf8);
formatted_value_utf8 = formatted_clean;
formatted_value_utf8 = tmp;
}
if (formatted_value_utf8 == NULL)
......
......@@ -995,3 +995,23 @@ _g_utf8_text_escape_xml (const char *str)
{
return _g_utf8_escape_xml_flags (str, XML_ESCAPE_TEXT);
}
char *
_g_utf8_remove_string_properties (const char *str)
{
const char *known_properties[] = { "lang=", "charset=" };
const char *after_properties = str;
int i;
for (i = 0; i < G_N_ELEMENTS (known_properties); /* void */) {
if (_g_utf8_has_prefix (after_properties, known_properties[i])) {
after_properties = _g_utf8_after_ascii_space (after_properties);
i = 0;
}
else
i++;
}
return (after_properties != NULL) ? g_strdup (after_properties) : NULL;
}
......@@ -96,6 +96,8 @@ char * _g_utf8_translate (const char *str,
...) G_GNUC_NULL_TERMINATED;
char * _g_utf8_escape_xml (const char *str);
char * _g_utf8_text_escape_xml (const char *str);
char * _g_utf8_remove_string_properties
(const char *str);
G_END_DECLS
......
......@@ -146,13 +146,12 @@ test_g_utf8_find_str (void)
static void
test_remove_lang_from_utf8_string (const char *value,
const char *expected)
test_remove_properties_from_utf8_string (const char *value,
const char *expected)
{
char *result = NULL;
if (_g_utf8_has_prefix (value, "lang="))
result = g_strdup (_g_utf8_after_ascii_space (value));
result = _g_utf8_remove_string_properties (value);
g_assert_cmpstr (result, ==, expected);
g_free (result);
......@@ -160,11 +159,20 @@ test_remove_lang_from_utf8_string (const char *value,
static void
test_remove_lang_from_utf8_string_all (void)
test_g_utf8_remove_string_properties (void)
{
test_remove_lang_from_utf8_string ("lang=EN hello", "hello");
test_remove_lang_from_utf8_string ("lang=FR langue d’oïl", "langue d’oïl");
test_remove_lang_from_utf8_string ("lang=正體字/繁體字 中华人民共和国", "中华人民共和国");
test_remove_properties_from_utf8_string (NULL, NULL);
test_remove_properties_from_utf8_string ("", "");
test_remove_properties_from_utf8_string ("正體字", "正體字");
test_remove_properties_from_utf8_string ("langue d’oïl", "langue d’oïl");
test_remove_properties_from_utf8_string ("lang=FR langue d’oïl", "langue d’oïl");
test_remove_properties_from_utf8_string ("lang=正體字/繁體字 中华人民共和国", "中华人民共和国");
test_remove_properties_from_utf8_string ("charset=UTF-8 langue d’oïl", "langue d’oïl");
test_remove_properties_from_utf8_string ("lang=FR charset=UTF-8 langue d’oïl", "langue d’oïl");
test_remove_properties_from_utf8_string ("charset=UTF-8 lang=FR langue d’oïl", "langue d’oïl");
test_remove_properties_from_utf8_string ("lang=FR charset=UTF-8 field=value langue d’oïl", "field=value langue d’oïl");
test_remove_properties_from_utf8_string ("lang=FR field=value charset=UTF-8 langue d’oïl", "field=value charset=UTF-8 langue d’oïl");
test_remove_properties_from_utf8_string ("field=value lang=FR charset=UTF-8 langue d’oïl", "field=value lang=FR charset=UTF-8 langue d’oïl");
}
......@@ -926,6 +934,7 @@ main (int argc,
g_test_add_func ("/glib-utils/_g_utf8_split_template", test_g_utf8_split_template_all);
g_test_add_func ("/glib-utils/_g_utf8_strip", test_g_utf8_strip_all);
g_test_add_func ("/glib-utils/_g_utf8_translate", test_g_utf8_translate_all);
g_test_add_func ("/glib-utils/_g_utf8_remove_string_properties", test_g_utf8_remove_string_properties);
g_test_add_func ("/glib-utils/_g_path_get_basename", test_g_path_get_basename_all);
g_test_add_func ("/glib-utils/_g_path_get_extension", test_g_path_get_extension_all);
......@@ -949,7 +958,6 @@ main (int argc,
g_test_add_func ("/glib-utils/_g_file_get_display_name", test_g_file_get_display_name_all);
g_test_add_func ("/glib-utils/_g_rand_string", test_g_rand_string);
g_test_add_func ("/glib-utils/regex", test_regexp);
g_test_add_func ("/glib-utils/remove_lang_from_utf8_string", test_remove_lang_from_utf8_string_all);
return g_test_run ();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment