//转换成功,测返回0
BOOL UTF8toAnsi(const char* utf8Str,unsigned short length)
{
unsigned short i;
char *unicodeStr;
unicodeStr = (char *)utf8Str;
WCHAR chr=0;
for (i=0;i<length;)
{
if ((0x80&utf8Str[i])==0) // ASCII
{
chr=utf8Str[i];
i++;
}
else if((0xE0&utf8Str[i])==0xC0) // 110xxxxx 10xxxxxx
{
chr =(utf8Str[i+0]&0x3F)<<6;
chr|=(utf8Str[i+1]&0x3F);
chr = ff_uni2oem(chr,0);
i+=2;
}
else if((0xF0&utf8Str[i])==0xE0) // 1110xxxx 10xxxxxx 10xxxxxx
{
chr =(utf8Str[i+0]&0x1F)<<12;
chr|=(utf8Str[i+1]&0x3F)<<6;
chr|=(utf8Str[i+2]&0x3F);
chr = ff_uni2oem(chr,0);
i+=3;
}
else // 不是UTF-8字符串
{
break;
}
if(chr&0xff00){
*unicodeStr++=(chr>>8);
}
*unicodeStr++=(char)chr;
}
return (i==length)?0:1;
}
char CheckType(const char* cue_buf)
{
unsigned short p;
p = *(unsigned short *)cue_buf;
if(p == 0xfeff){
return TYPE_UNICODE;
}else if(p == 0xfffe){
return TYPE_UNICODE_BIG;
}else if(p == 0xbbef){
return TYPE_UTF_8_BOM;
}else{
return TYPE_ANSI;
}
}
BOOL CheckUTF8(const char* AnsiStr,unsigned int length)
{
unsigned int i=0;
BOOL isUTF8=TRUE;
while (i<length)
{
if ((0x80&AnsiStr[i])==0) // ASCII
{
i++;
continue;
}
else if((0xE0&AnsiStr[i])==0xC0) // 110xxxxx
{
if (AnsiStr[i+1]=='\0')
{
isUTF8=FALSE;
break;
}
if ((0xC0&AnsiStr[i+1])==0x80) // 10xxxxxx
{
i+=2;
continue;
}
else
{
isUTF8=FALSE;
break;
}
}
else if((0xF0&AnsiStr[i])==0xE0) // 1110xxxx
{
if (AnsiStr[i+1]=='\0')
{
isUTF8=FALSE;
break;
}
if (AnsiStr[i+2]=='\0')
{
isUTF8=FALSE;
break;
}
if (((0xC0&AnsiStr[i+1])==0x80)&&((0xC0&AnsiStr[i+2])==0x80)) // 10xxxxxx 10xxxxxx
{
i+=3;
continue;
}
else
{
isUTF8=FALSE;
break;
}
}
else // 不是UTF-8字符串
{
isUTF8=FALSE;
break;
}
}
return isUTF8;
}