private static bool GetEncoding() { try { IntPtr info_ptr = mecab_dictionary_info(mecab); mecab_dictionary_info_t info = new mecab_dictionary_info_t(); Marshal.PtrToStructure(info_ptr, info); string charset = Marshal.PtrToStringAnsi(info.charset); if (charset == "SHIFT-JIS") { MecabEncoding = Encoding.GetEncoding(932); } else if (charset == "EUC-JP") { MecabEncoding = Encoding.GetEncoding(20932); } else if (charset == "UTF-8") { MecabEncoding = Encoding.UTF8; } else { throw new Exception(string.Format("MeCab dictionary encoding {0} is not supported.", charset)); } return(true); } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } }
private static bool GetEncoding() { try { IntPtr info_ptr = mecab_dictionary_info(mecab); mecab_dictionary_info_t info = new mecab_dictionary_info_t(); Marshal.PtrToStructure(info_ptr, info); string charset = Marshal.PtrToStringAnsi(info.charset); if (charset == "SHIFT-JIS") MecabEncoding = Encoding.GetEncoding(932); else if (charset == "EUC-JP") MecabEncoding = Encoding.GetEncoding(20932); else if (charset == "UTF-8") MecabEncoding = Encoding.UTF8; else throw new Exception(string.Format("MeCab dictionary encoding {0} is not supported.", charset)); return true; } catch (Exception ex) { MessageBox.Show(ex.Message); return false; } }