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
This commit is contained in:
28
src/path.c
28
src/path.c
@@ -20,6 +20,7 @@
|
||||
#include "log.h"
|
||||
#include "charConv.h"
|
||||
#include "conf.h"
|
||||
#include "utf8.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -46,24 +47,35 @@ char * pathConvCharset(char * to, char * from, char * str, char * ret) {
|
||||
ret = convStrDup(str);
|
||||
}
|
||||
|
||||
if(!ret) ret = strdup(str);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char * fsCharsetToUtf8(char * str) {
|
||||
static char * ret = NULL;
|
||||
|
||||
return ret = pathConvCharset("UTF-8",fsCharset,str,ret);
|
||||
ret = pathConvCharset("UTF-8",fsCharset,str,ret);
|
||||
|
||||
if(ret && !validUtf8String(ret)) ret = NULL;
|
||||
/*if(!ret) ret = asciiStrToUtf8Dup(str);*/
|
||||
|
||||
/* if all else fails, just strdup */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char * utf8ToFsCharset(char * str) {
|
||||
static char * ret = NULL;
|
||||
|
||||
return ret = pathConvCharset(fsCharset,"UTF-8",str,ret);
|
||||
ret = pathConvCharset(fsCharset,"UTF-8",str,ret);
|
||||
|
||||
if(!ret) ret = strdup(str);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void setFsCharset(char * charset) {
|
||||
int error = 0;
|
||||
|
||||
if(fsCharset) free(fsCharset);
|
||||
|
||||
fsCharset = strdup(charset);
|
||||
@@ -74,11 +86,19 @@ void setFsCharset(char * charset) {
|
||||
ERROR("fs charset conversion problem: "
|
||||
"not able to convert from \"%s\" to \"%s\"\n",
|
||||
fsCharset,"UTF-8");
|
||||
error = 1;
|
||||
}
|
||||
if(setCharSetConversion(fsCharset,"UTF-8")!=0) {
|
||||
ERROR("fs charset conversion problem: "
|
||||
"not able to convert from \"%s\" to \"%s\"\n",
|
||||
"UTF-8",fsCharset);
|
||||
error = 1;
|
||||
}
|
||||
|
||||
if(error) {
|
||||
free(fsCharset);
|
||||
ERROR("setting fs charset to ISO-8859-1!\n");
|
||||
fsCharset = strdup("ISO-8859-1");
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user