Analyser

Analyser — Basic analyser interface.

Description

Basically you want to allocate an analyser with enca_analyser_alloc() for some language, use enca_analyse() (or enca_analyse_const()) on a buffer to find its encoding, and interpret the results with something like enca_charset_name(). The analyser then can be used for another buffer. Once you no longer need it, call enca_analyser_free() to release it. A single working example is better than a hundred pages of reference manual.

A minimal Enca library application – Czech encoding detector.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
#include <enca.h>
int main(void)
{
EncaAnalyser analyser;
EncaEncoding encoding;
unsigned char buffer[4096];
size_t buflen;

buflen = fread(buffer, 1, 4096, stdin);
analyser = enca_analyser_alloc("cs");
encoding = enca_analyse(analyser, buffer, buflen);
printf("Charset: %s\n", enca_charset_name(encoding.charset,
                                             ENCA_NAME_STYLE_HUMAN));
enca_analyser_free(analyser);

return 0;
}

Functions