aboutsummaryrefslogtreecommitdiffstats
path: root/src/tag/TagString.cxx
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tag/TagString.cxx33
1 files changed, 24 insertions, 9 deletions
diff --git a/src/tag/TagString.cxx b/src/tag/TagString.cxx
index 3e8d8c1b0..0c3868eb5 100644
--- a/src/tag/TagString.cxx
+++ b/src/tag/TagString.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * Copyright (C) 2003-2014 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -19,11 +19,17 @@
#include "config.h"
#include "TagString.hxx"
+#include "util/Alloc.hxx"
+#ifdef HAVE_GLIB
#include <glib.h>
+#endif
#include <assert.h>
#include <string.h>
+#include <stdlib.h>
+
+#ifdef HAVE_GLIB
/**
* Replace invalid sequences with the question mark.
@@ -33,7 +39,7 @@ patch_utf8(const char *src, size_t length, const gchar *end)
{
/* duplicate the string, and replace invalid bytes in that
buffer */
- char *dest = g_strdup(src);
+ char *dest = xstrdup(src);
do {
dest[end - src] = '?';
@@ -58,15 +64,20 @@ fix_utf8(const char *str, size_t length)
/* no, it's not - try to import it from ISO-Latin-1 */
temp = g_convert(str, length, "utf-8", "iso-8859-1",
nullptr, &written, nullptr);
- if (temp != nullptr)
+ if (temp != nullptr) {
/* success! */
- return temp;
+ char *p = xstrdup(temp);
+ g_free(temp);
+ return p;
+ }
/* no, still broken - there's no medication, just patch
invalid sequences */
return patch_utf8(str, length, end);
}
+#endif
+
static bool
char_is_non_printable(unsigned char ch)
{
@@ -96,7 +107,7 @@ clear_non_printable(const char *p, size_t length)
if (first == nullptr)
return nullptr;
- dest = g_strndup(p, length);
+ dest = xstrndup(p, length);
for (size_t i = first - p; i < length; ++i)
if (char_is_non_printable(dest[i]))
@@ -108,19 +119,23 @@ clear_non_printable(const char *p, size_t length)
char *
FixTagString(const char *p, size_t length)
{
- char *utf8, *cleared;
+#ifdef HAVE_GLIB
+ // TODO: implement without GLib
- utf8 = fix_utf8(p, length);
+ char *utf8 = fix_utf8(p, length);
if (utf8 != nullptr) {
p = utf8;
length = strlen(p);
}
+#endif
- cleared = clear_non_printable(p, length);
+ char *cleared = clear_non_printable(p, length);
+#ifdef HAVE_GLIB
if (cleared == nullptr)
cleared = utf8;
else
- g_free(utf8);
+ free(utf8);
+#endif
return cleared;
}