compact_enc_det是google的开源编码检测项目,开源与github:
https://github.com/google/compact_enc_det.git
compact_enc_det可以用来检测给定的文本文件的编码类型,支持多种类型的文本:
enum TextCorpusType {
WEB_CORPUS,
XML_CORPUS,
QUERY_CORPUS, // Use this for vanilla plaintext
EMAIL_CORPUS,
NUM_CORPA, // always last
};
其主要的检测编码的方法描述如下:
Encoding DetectEncoding(
const char* text, int text_length, const char* url_hint,
const char* http_charset_hint, const char* meta_charset_hint,
const int encoding_hint,
const Language language_hint, // User interface lang
const TextCorpusType corpus_type, bool ignore_7bit_mail_encodings,
int* bytes_consumed, bool* is_reliable);
在linux上将这个 项目编译成 动态链接库的步骤如下:
1. 下载代码:git clone https://github.com/google/compact_enc_det.git
2. 进入项目目录 cd compact_enc_det/
3. 执行编译命令 :
g++ -shared -Wno-narrowing -fPIC -o encod.so ./compact_enc_det/compact_enc_det.cc ./compact_enc_det/compact_enc_det_hint_code.cc ./util/encodings/encodings.cc ./util/languages/languages.cc -I ./ --std=c++11
此文不介绍 g++命令细节哦
到此就可以得到 encod.so 文件,这个文件就是我们要用的动态链接库文件。