int CCheckSensitiveWord::ReadSenSitiveWordFromFile( CString &strPath)
{
try
{
char ch[MAXTXTLEN]=("\0");
WideCharToMultiByte ( CP_OEMCP,NULL, strPath.GetBuffer(0),-1,ch,strPath.GetLength()*2,NULL,FALSE);
FILE *fpp = fopen(ch, ("r"));
if (fpp == NULL)
{
return 0;
}
// int iFlag= IsUTF8File(strPath.GetBuffer(0));
// int iFileFlag = CP_ACP;
// if (iFlag > 0)
// {
// iFileFlag = CP_UTF8;
// }
char chLine = 0;
char chWord[MAXTXTLEN];
TCHAR chhWord[MAXTXTLEN];
memset(chWord,'\0', MAXTXTLEN);
memset(chhWord, _T('\0'), MAXTXTLEN);
char *pCh = chWord;
char chT =10;
int i = 0;
m_ErrorNum = 0; //初始化长度大于128的字符
int iTemp = 0;
do
{
fread(pCh, 1, 1, fpp);
if (iTemp <3 )//如果是utf_8文件
{
// i--;
iTemp ++;
continue;
}
i++;
if (feof(fpp))
{
*pCh = 10;
}
if (*pCh == 10)//表示读取的是换行符
{
if(i != 1) //表示读取了一行数据
{
*pCh='\0';
memset(chhWord, _T('\0'), MAXTXTLEN);
int wcsLen = ::MultiByteToWideChar(CP_UTF8, NULL, chWord, strlen(chWord), NULL, 0);
MultiByteToWideChar( CP_UTF8, 0, chWord, strlen(chWord), chhWord, wcsLen ) ;
CString strTemp( chhWord ,wcsLen);
int iFRet = FormatWord(strTemp);
if (-2 == iFRet)
{
m_ErrorNum++;
chhWord[wcsLen]=_T('\0');
EBOOK_LOG(LOG_INFO,_T("senseitive word len > 128 \n word=%s"),chhWord);
}
else if (iFRet > 0)
{
m_SetWord.insert(strTemp);
}
memset(chWord,'\0', MAXTXTLEN);
}
i = 0;
pCh = chWord;
if (feof(fpp))
{
break;
}
continue;
}
pCh++;
} while (TRUE) ;
fclose(fpp);
}
catch (CException* e)
{
return 0;//读取异常
}
return 1;//成功
}