aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/tag.c40
-rw-r--r--src/utils.c7
-rw-r--r--src/utils.h2
3 files changed, 22 insertions, 27 deletions
diff --git a/src/tag.c b/src/tag.c
index 3f7720d88..dbf4a098f 100644
--- a/src/tag.c
+++ b/src/tag.c
@@ -19,7 +19,6 @@
#include "tag.h"
#include "tag_internal.h"
#include "tag_pool.h"
-#include "utils.h"
#include "log.h"
#include "conf.h"
#include "song.h"
@@ -358,7 +357,7 @@ int tag_equal(const struct tag *tag1, const struct tag *tag2)
}
static char *
-fix_utf8(const char *str, size_t *length_r)
+fix_utf8(const char *str, size_t length)
{
char *temp;
GError *error = NULL;
@@ -366,18 +365,17 @@ fix_utf8(const char *str, size_t *length_r)
assert(str != NULL);
- if (g_utf8_validate(str, *length_r, NULL))
+ if (g_utf8_validate(str, length, NULL))
return NULL;
DEBUG("not valid utf8 in tag: %s\n",str);
- temp = g_convert(str, *length_r, "utf-8", "iso-8859-1",
+ temp = g_convert(str, length, "utf-8", "iso-8859-1",
NULL, &written, &error);
if (temp == NULL) {
g_error_free(error);
return NULL;
}
- *length_r = written;
return temp;
}
@@ -413,22 +411,28 @@ void tag_end_add(struct tag *tag)
#endif
}
+static char *
+fix_tag_value(const char *p, size_t length)
+{
+ char *utf8, *escaped;
+
+ utf8 = fix_utf8(p, length);
+ if (utf8 == NULL)
+ utf8 = g_strndup(p, length);
+
+ escaped = g_strescape(utf8, NULL);
+ g_free(utf8);
+
+ return escaped;
+}
+
static void appendToTagItems(struct tag *tag, enum tag_type type,
const char *value, size_t len)
{
unsigned int i = tag->numOfItems;
- char *duplicated;
- const char *p;
-
- p = duplicated = fix_utf8(value, &len);
- if (p == NULL)
- p = value;
- if (memchr(p, '\n', len) != NULL) {
- if (duplicated == NULL)
- p = duplicated = g_strndup(p, len);
+ char *p;
- stripReturnChar(duplicated);
- }
+ p = fix_tag_value(value, len);
tag->numOfItems++;
@@ -445,10 +449,10 @@ static void appendToTagItems(struct tag *tag, enum tag_type type,
}
g_mutex_lock(tag_pool_lock);
- tag->items[i] = tag_pool_get_item(type, p, len);
+ tag->items[i] = tag_pool_get_item(type, p, strlen(p));
g_mutex_unlock(tag_pool_lock);
- g_free(duplicated);
+ g_free(p);
}
void tag_add_item_n(struct tag *tag, enum tag_type itemType,
diff --git a/src/utils.c b/src/utils.c
index 4815a0bc1..c30712660 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -40,13 +40,6 @@
#include <windows.h>
#endif
-void stripReturnChar(char *string)
-{
- while (string && (string = strchr(string, '\n'))) {
- *string = ' ';
- }
-}
-
void my_usleep(long usec)
{
#ifdef WIN32
diff --git a/src/utils.h b/src/utils.h
index 0e210cd5f..dff41bab6 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -36,8 +36,6 @@
} while (0)
#endif /* !assert_static */
-void stripReturnChar(char *string);
-
void my_usleep(long usec);
/* trivial functions, keep them inlined */