|
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
">
AnalyserSynopsis
DescriptionA single working example is better than a hundred pages of reference manual, so: Example 1. A minimal Enca library application – Czech encoding detector.
The analyser has plenty of options, but generally you don't need to fiddle with them, except enca_set_termination_strictness(). Detailsenca_analyser_alloc ()
Allocates an analyser and initializes it for language language. The analyser, once crerated, can be used only for language for which it was initialized. If you need to detect encodings of texts in more than one language, you must allocate an analyser for each one. langname is two-letter ISO 639:1989 language code. Locale names in form language_territory and ISO-639 English language names also may be accepted in the future. To be on the safe side, use only names returned by enca_get_languages(). enca_analyser_free ()
Frees memory used by EncaAnalyser analyser. enca_analyse ()
Analyses buffer and finds its encoding. The buffer is checked for 8bit encodings of language for which analyser was initialized and for multibyte encodings, mostly independent on language (unless disabled with enca_set_multibyte()). The contents of buffer may be (and probably will be) modified during the analyse. Use enca_analyse_const() instead if this discomforts you.
enca_analyse_const ()
Analyses buffer and finds its encoding. The buffer is checked for 8bit encodings of language for which analyser was initialized and for multibyte encodings, mostly independent on language (unless disabled with enca_set_multibyte()). This function never modifies buffer (can be even used with string literal buffer) at the expense it's generally slower than enca_analyse().
enca_errno ()
Returns analyser error code. The error code is not modified. However, any other analyser call i.e. call to a function taking analyser as parameter can change the error code. enca_strerror ()
Returns string describing the error code. The returned string must be considered constant and must NOT be freed. It is however gauranteed not to be modified on invalidated by subsequent calls to any libenca functions, including enca_strerror(). The analyser error code is not changed for a successful call, and it set to ENCA_EINVALUE upon error. enca_double_utf8_check ()
Checks buffer for double-UTF-8 encoding. Double-UTF-8 encoding is result of converting UTF-8 text to UTF-8 again, as if it was some 8bit charset. This is quite hard to recover from. The analayser mostly only determines the language, the rest of the test is independent on the main guessing routines. When buffer doesn't containing UTF-8 text, the result is undefined. Calling this function when language is `none' has currently no effect.
enca_double_utf8_get_candidates ()
Returns array of Double-UTF-8 source charset candidates from last check. The size of the array is the return value of enca_double_utf8_check(). It must be freed by caller. Must not be called if no Double-UTF-8 test has been performed yet. When called after unsuccessfull Double-UTF-8 test, it returns NULL, but the result after unsuccessfull call should be considered undefined.
enca_set_multibyte ()
Enables or disables multibyte encoding tests for analyser. This option is enabled by default. When multibyte encodings are disabled, only 8bit charsets are checked. Disabling them for language with no 8bit charsets leaves only one thing enca_analyse() could test: whether the sample is purely 7bit ASCII or not (the latter leading to analyser failure, of course). Multibyte encoding detection is also affected by enca_set_termination_strictness(). enca_set_interpreted_surfaces ()
Enables or disables interpeted surfaces tests for analyser. This option is enabled by default. To allow simple applications which care about charset only and don't want to wrestle with surfaces, neglecting surface information should not have serious consequences. While ignoring EOL type surface is feasible, and ignoring UCS byteorders may be acceptable in endian-homogenous environment; ignoring the fact file is Quoted-Printable encoded can have disasterous consequences. By disabling this option you can disable surfaces requiring fundamental reinterpretation of the content, namely ENCA_SURFACE_QP and ENCA_SURFACE_EOL_BIN (thus probably making enca_analyse() to fail on such samples). enca_set_ambiguity ()
Enables or disables ambiguous mode for analyser. This option is disabled by default. In ambiguous mode some result is returned even when the charset cannot be determined uniquely, provided that sample contains only characters which have the same meaning in all charsets under consideration. enca_set_filtering ()
Enables or disables filters for analyser. This option is enabled by default. Various filters are used to filter out block of binary noise and box-drawing characters which can confuse enca. In cases this is unwanted, you can disable them by setting this option to zero. enca_set_garbage_test ()
Enables or disables garbage test for analyser. This option is enabled by default. To prevent white noise (and almost-white noise) from being accidentally detected as some charset, a garbage test is used. In cases this is unwanted, you can disable is by setting this option to zero. enca_set_termination_strictness ()
Enables or disables requiring multibyte sequences to be terminated correctly at the end of sample. This option is enabled by default. The sample given to enca_analyse() generally may not be whole text (e.g. for efficiency reasons). As a result, it may end in the middle of a multibyte sequence. In this case, you should disable this option to prevent rejecting some charset just because the sample don't terminate correctly. On the other hand, when given sample contains whole text, you should always enable this option to assure correctness of the result. Note this option doesn't affect fixed character size encodings, like UCS-2 and UCS-4; sample is never assumed to contain UCS-2 text when its size is not even (and similarly for UCS-4). enca_set_significant ()
Sets the minimal number of required significant characters. The default value of this option is 10. enca_analyse() refuses to make a decision unles at least this number of significant characters is found in sample. You may want to lower this number for very short texts. enca_set_threshold ()
Sets the minimal ratio between the most probable and the second most probable charsets. The default value of this option is 1.4142. enca_analyse() consideres the result known only when there's a clear gap between the most probable and the second most probable charset proabailities. Lower threshold values mean larger probability of a mistake and smaller probability of not recognizing a charset; higher threshold values the contrary. |