diff --git a/src/misc.c b/src/misc.c index ba17e476..09c9af57 100644 --- a/src/misc.c +++ b/src/misc.c @@ -33,6 +33,9 @@ #include #include +#include +#include + #include "logger.h" #include "misc.h" @@ -274,6 +277,32 @@ m_realpath(const char *pathname) return ret; } +char * +unicode_fixup_string(char *str) +{ + uint8_t *ret; + size_t len; + + if (!str) + return NULL; + + len = strlen(str); + + /* String is valid UTF-8 */ + if (!u8_check((uint8_t *)str, len)) + return str; + + ret = u8_conv_from_encoding("ascii", iconveh_question_mark, str, len, NULL, NULL, &len); + if (!ret) + { + DPRINTF(E_LOG, L_MISC, "Could not convert string '%s' to UTF-8: %s\n", str, strerror(errno)); + + return NULL; + } + + return (char *)ret; +} + uint32_t djb_hash(void *data, size_t len) { diff --git a/src/misc.h b/src/misc.h index 0e821dff..65818a95 100644 --- a/src/misc.h +++ b/src/misc.h @@ -25,6 +25,9 @@ safe_hextou64(const char *str, uint64_t *val); char * m_realpath(const char *pathname); +char * +unicode_fixup_string(char *str); + uint32_t djb_hash(void *data, size_t len);