When clucene is compatible with the index file generated by Lucene, the encoding conversion problem occurs. Their compatibility may have such problems for non-English encoding.ProgramIt is found that it uses unicode encoding to save. Therefore, you must first convert the string or file into unicode encoding and then perform other processing.
Conversion detailsCodeAs follows (tested in Linux and vc6.0 ):
# Ifndef _ Unix
Static inline int codePage (const char * code_page)
{
Return 936; // "GBK"
}
# Endifstatic inline int mb2wc (const char * code_page,/* In */const char * In, int in_len,
/* Out */wchar_t * Out, int out_max)
{
# Ifdef _ Unix
Size_t result;
Iconv_t env;
ENV = iconv_open ("wchar_t", code_page );
Result = iconv (ENV, (char **) & in, (size_t *) & in_len, (char **) & out, (size_t *) & out_max );
Iconv_close (ENV );
Return (INT) result;
# Else
Return: multibytetowidechar (codePage (code_page), 0, In, in_len, out, out_max );
# Endif
} Static inline int wc2mb (const char * code_page,/* In */const wchar_t * In, int in_len,
/* Out */char * Out, int out_max)
{
# Ifdef _ Unix
Size_t result;
Iconv_t env;
ENV = iconv_open (code_page, "wchar_t ");
Result = iconv (ENV, (char **) & in, (size_t *) & in_len, (char **) & out, (size_t *) & out_max );
Iconv_close (ENV );
Return (INT) result;
# Else
Return: widechartomultibyte (codePage (code_page), 0, in,-1, out, out_max, null, null );
# Endif
} Void str_to_unicodechar (const char * strin, tchar * & Strout ){
If (! Strin)
Return; int I = mb2wc ("936", (char *) strin,-1, null, 0 );
Strout = (tchar *) malloc (sizeof (tchar) * I );
Mb2wc ("936", (char *) strin,-1, Strout, I );
}
Void unicodechar_to_str (const tchar * strin, char * & Strout ){
If (! Strin)
Return;
Int I = wc2mb ("936", strin,-1, null, 0 );
Strout = new char [I + 1];
Wc2mb ("936", strin,-1, Strout, I );
Strout [I] = 0;
} Void tchar_to_str (const tchar * strin, char * & Strout ){
Int I = 0;
If (! Strin)
Return;
Strout = new char [1024];
While (* strin ){
Strout [I] = * strin ++;
I ++;
}
Strout [I] = '\ 0 ';
}