rename all ascii/utf8 stuff to latin1/utf8

git-svn-id: https://svn.musicpd.org/mpd/trunk@718 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-04-13 13:52:16 +00:00
parent 4920ee719a
commit 8c96c2d363
5 changed files with 27 additions and 31 deletions

View File

@ -34,10 +34,10 @@ char * char_conv_from = NULL;
mpd_sint8 char_conv_same = 0; mpd_sint8 char_conv_same = 0;
mpd_sint8 char_conv_use_iconv = 0; mpd_sint8 char_conv_use_iconv = 0;
/* 1 is to use asciiToUtf8 /* 1 is to use latin1ToUtf8
0 is not to use ascii/utf8 converter 0 is not to use latin1/utf8 converter
-1 is to use utf8ToAscii*/ -1 is to use utf8ToLatin1*/
mpd_sint8 char_conv_asciiToUtf8 = 0; mpd_sint8 char_conv_latin1ToUtf8 = 0;
#define BUFFER_SIZE 1024 #define BUFFER_SIZE 1024
@ -58,13 +58,13 @@ int setCharSetConversion(char * to, char * from) {
} }
if(strcmp(to,"UTF-8")==0 && strcmp(from,"ISO-8859-1")==0) { if(strcmp(to,"UTF-8")==0 && strcmp(from,"ISO-8859-1")==0) {
char_conv_asciiToUtf8 = 1; char_conv_latin1ToUtf8 = 1;
} }
else if(strcmp(to,"ISO-8859-1")==0 && strcmp(from,"UTF-8")==0) { else if(strcmp(to,"ISO-8859-1")==0 && strcmp(from,"UTF-8")==0) {
char_conv_asciiToUtf8 = -1; char_conv_latin1ToUtf8 = -1;
} }
if(char_conv_asciiToUtf8!=0) { if(char_conv_latin1ToUtf8!=0) {
char_conv_to = strdup(to); char_conv_to = strdup(to);
char_conv_from = strdup(from); char_conv_from = strdup(from);
return 0; return 0;
@ -121,12 +121,12 @@ char * convStrDup(char * string) {
} }
#endif #endif
switch(char_conv_asciiToUtf8) { switch(char_conv_latin1ToUtf8) {
case 1: case 1:
return asciiStrToUtf8Dup(string); return latin1StrToUtf8Dup(string);
break; break;
case -1: case -1:
return utf8StrToAsciiDup(string); return utf8StrToLatin1Dup(string);
break; break;
} }
@ -143,7 +143,7 @@ void closeCharSetConversion() {
char_conv_to = NULL; char_conv_to = NULL;
char_conv_from = NULL; char_conv_from = NULL;
char_conv_same = 0; char_conv_same = 0;
char_conv_asciiToUtf8 = 0; char_conv_latin1ToUtf8 = 0;
char_conv_use_iconv = 0; char_conv_use_iconv = 0;
} }
} }

View File

@ -20,7 +20,6 @@
#include "log.h" #include "log.h"
#include "charConv.h" #include "charConv.h"
#include "conf.h" #include "conf.h"
#include "utf8.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -59,9 +58,6 @@ char * fsCharsetToUtf8(char * str) {
free(ret); free(ret);
ret = NULL; ret = NULL;
} }
/*if(!ret) ret = asciiStrToUtf8Dup(str);*/
/* if all else fails, just strdup */
return ret; return ret;
} }

View File

@ -63,7 +63,7 @@ void printMpdTag(FILE * fp, MpdTag * tag) {
if(str && !validUtf8String(str)) { \ if(str && !validUtf8String(str)) { \
char * temp; \ char * temp; \
DEBUG("not valid utf8 in tag: %s\n",str); \ DEBUG("not valid utf8 in tag: %s\n",str); \
temp = asciiStrToUtf8Dup(str); \ temp = latin1StrToUtf8Dup(str); \
free(str); \ free(str); \
str = temp; \ str = temp; \
} \ } \

View File

@ -4,7 +4,7 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
unsigned char * asciiToUtf8(unsigned char c) { unsigned char * latin1ToUtf8(unsigned char c) {
static unsigned char utf8[3]; static unsigned char utf8[3];
memset(utf8,0,3); memset(utf8,0,3);
@ -22,9 +22,9 @@ unsigned char * asciiToUtf8(unsigned char c) {
return utf8; return utf8;
} }
unsigned char * asciiStrToUtf8Dup(unsigned char * ascii) { unsigned char * latin1StrToUtf8Dup(unsigned char * latin1) {
/* utf8 should have at most two char's per ascii char */ /* utf8 should have at most two char's per latin1 char */
int len = strlen(ascii)*2+1; int len = strlen(latin1)*2+1;
unsigned char * ret = malloc(len); unsigned char * ret = malloc(len);
unsigned char * cp = ret; unsigned char * cp = ret;
unsigned char * utf8; unsigned char * utf8;
@ -33,19 +33,19 @@ unsigned char * asciiStrToUtf8Dup(unsigned char * ascii) {
len = 0; len = 0;
while(*ascii) { while(*latin1) {
utf8 = asciiToUtf8(*ascii); utf8 = latin1ToUtf8(*latin1);
while(*utf8) { while(*utf8) {
*(cp++) = *(utf8++); *(cp++) = *(utf8++);
len++; len++;
} }
ascii++; latin1++;
} }
return realloc(ret,len+1); return realloc(ret,len+1);
} }
unsigned char utf8ToAscii(unsigned char * utf8) { unsigned char utf8ToLatin1(unsigned char * utf8) {
unsigned char c = 0; unsigned char c = 0;
if(utf8[0]<128) return utf8[0]; if(utf8[0]<128) return utf8[0];
@ -86,8 +86,8 @@ int validUtf8String(unsigned char * string) {
return 1; return 1;
} }
unsigned char * utf8StrToAsciiDup(unsigned char * utf8) { unsigned char * utf8StrToLatin1Dup(unsigned char * utf8) {
/* utf8 should have at most two char's per ascii char */ /* utf8 should have at most two char's per latin1 char */
int len = strlen(utf8)+1; int len = strlen(utf8)+1;
unsigned char * ret = malloc(len); unsigned char * ret = malloc(len);
unsigned char * cp = ret; unsigned char * cp = ret;
@ -103,7 +103,7 @@ unsigned char * utf8StrToAsciiDup(unsigned char * utf8) {
free(ret); free(ret);
return NULL; return NULL;
} }
*(cp++) = utf8ToAscii(utf8); *(cp++) = utf8ToLatin1(utf8);
utf8+= count; utf8+= count;
len++; len++;
} }

View File

@ -1,13 +1,13 @@
#ifndef UTF_8_H #ifndef UTF_8_H
#define UTF_8_H #define UTF_8_H
unsigned char * asciiToUtf8(unsigned char c); unsigned char * latin1ToUtf8(unsigned char c);
unsigned char * asciiStrToUtf8Dup(unsigned char * ascii); unsigned char * latin1StrToUtf8Dup(unsigned char * latin1);
unsigned char * utf8StrToAsciiDup(unsigned char * utf8); unsigned char * utf8StrToLatin1Dup(unsigned char * utf8);
unsigned char utf8ToAscii(unsigned char * utf8); unsigned char utf8ToLatin1(unsigned char * utf8);
int validateUtf8Char(unsigned char * utf8Char); int validateUtf8Char(unsigned char * utf8Char);