From 1004890e253453faba81126028986f075e5fc5e7 Mon Sep 17 00:00:00 2001 From: Warren Dukes Date: Tue, 13 Apr 2004 04:59:57 +0000 Subject: lots of fsCharset, utf8/ascii converting clean-up and robustness stuff Also, if fsCharsetToUtf8 can't convert to valid UTF-8, then don't add it to the db, this way clients don't have to worry about weirdness and it will force ppl to convert it. git-svn-id: https://svn.musicpd.org/mpd/trunk@711 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/utf8.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/utf8.c') diff --git a/src/utf8.c b/src/utf8.c index 140316150..4b8814a80 100644 --- a/src/utf8.c +++ b/src/utf8.c @@ -85,3 +85,28 @@ int validUtf8String(unsigned char * string) { return 1; } + +unsigned char * utf8StrToAsciiDup(unsigned char * utf8) { + /* utf8 should have at most two char's per ascii char */ + int len = strlen(utf8)+1; + unsigned char * ret = malloc(len); + unsigned char * cp = ret; + int count; + + memset(ret,0,len); + + len = 0; + + while(*utf8) { + count = validateUtf8Char(utf8); + if(!count) { + free(ret); + return NULL; + } + *(cp++) = utf8ToAscii(utf8); + utf8+= count; + len++; + } + + return realloc(ret,len+1); +} -- cgit v1.2.3