mirror of
https://github.com/owntone/owntone-server.git
synced 2025-02-04 10:26:02 -05:00
Add unicode_fixup_string() to check & reencode UTF-8 strings
This commit is contained in:
parent
9186ebaa89
commit
da0c10a392
29
src/misc.c
29
src/misc.c
@ -33,6 +33,9 @@
|
||||
#include <limits.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <unistr.h>
|
||||
#include <uniconv.h>
|
||||
|
||||
#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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user