TagString: disable UTF-8 validation if GLib is disabled

This commit is contained in:
Max Kellermann 2014-02-17 22:33:10 +01:00
parent 91729437a0
commit 6a08f2281a

View File

@ -21,12 +21,16 @@
#include "TagString.hxx" #include "TagString.hxx"
#include "util/Alloc.hxx" #include "util/Alloc.hxx"
#ifdef HAVE_GLIB
#include <glib.h> #include <glib.h>
#endif
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_GLIB
/** /**
* Replace invalid sequences with the question mark. * Replace invalid sequences with the question mark.
*/ */
@ -72,6 +76,8 @@ fix_utf8(const char *str, size_t length)
return patch_utf8(str, length, end); return patch_utf8(str, length, end);
} }
#endif
static bool static bool
char_is_non_printable(unsigned char ch) char_is_non_printable(unsigned char ch)
{ {
@ -113,19 +119,23 @@ clear_non_printable(const char *p, size_t length)
char * char *
FixTagString(const char *p, size_t length) 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) { if (utf8 != nullptr) {
p = utf8; p = utf8;
length = strlen(p); length = strlen(p);
} }
#endif
cleared = clear_non_printable(p, length); char *cleared = clear_non_printable(p, length);
#ifdef HAVE_GLIB
if (cleared == nullptr) if (cleared == nullptr)
cleared = utf8; cleared = utf8;
else else
free(utf8); free(utf8);
#endif
return cleared; return cleared;
} }