C 文字列操作 新しいページはコチラ
提供: yonewiki
(→文字列ファイルへの入出力) |
(→文字列ファイルへの入出力) |
||
5,172行: | 5,172行: | ||
int32_t int32FindCharSetCnt = 0; | int32_t int32FindCharSetCnt = 0; | ||
int32_t int32Confidence = 0; | int32_t int32Confidence = 0; | ||
− | const UCharsetMatch | + | const UCharsetMatch* pucsetmatchStrCode = ucsdet_detect(pucsetdetecDetector, &uerrorNum); |
+ | const UCharsetMatch** ppucsetmatchStrCode = ucsdet_detectAll(pucsetdetecDetector, &int32FindCharSetCnt, &uerrorNum); | ||
+ | |||
const char* cpcDetectStrCodeName; | const char* cpcDetectStrCodeName; | ||
const char* cpcDetectStrCodeLanguage; | const char* cpcDetectStrCodeLanguage; | ||
− | cpcDetectStrCodeName = ucsdet_getName( | + | for(int i = 0; i < int32FindCharSetCnt; i++){ |
− | + | int32Confidence = ucsdet_getConfidence(ppucsetmatchStrCode[i], &uerrorNum);0~100で表される信頼値 | |
− | + | cpcDetectStrCodeName = ucsdet_getName(ppucsetmatchStrCode[i], &uerrorNum);//文字コード名 ICUの文字コードセット名に適した形式。 | |
+ | cpcDetectStrCodeLanguage = ucsdet_getLanguage(ppucsetmatchStrCode[i], &uerrorNum); | ||
+ | printf("CodeConf->%d\n",int32Confidence); | ||
+ | printf("CodeName->%s\n",cpcDetectStrCodeName); | ||
+ | printf("CodeLang->%s\n",cpcDetectStrCodeLanguage);//RFC3066コードを取得できる。 | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | のようにするとConfidenceの値が大きいほど一致率が高いものとして確認ができます。全部を一覧するにはfor文で0~int32FindCharSetCnt -1までの要素を確認するとよいです。 | ||
+ | 出力結果 UTF-16LEのファイル。 | ||
+ | <syntaxhighlight lang="text"> | ||
+ | CodeConf->100 | ||
+ | CodeName->UTF-16LE | ||
+ | CodeLang-> | ||
+ | CodeConf->23 | ||
+ | CodeName->windows-1252 | ||
+ | CodeLang->es | ||
+ | CodeConf->23 | ||
+ | CodeName->windows-1250 | ||
+ | CodeLang->cs | ||
+ | CodeConf->10 | ||
+ | CodeName->UTF-16BE | ||
+ | CodeLang-> | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | となります。 | |
=='''文字列と数値の変換'''== | =='''文字列と数値の変換'''== |