| 1 |
-----------Summary |
| 2 |
Charset Detector - as the name says - is a stand alone component for automatic charset detection of a given text. |
| 3 |
It can be useful for internationalisation support in multilingual applications such as web-script editors or Unicode editors. |
| 4 |
Given input buffer will be analysed to guess used encoding. The result can be used as control parameter for charset conversation procedure. |
| 5 |
Based on Mozilla's i18n component - https://dxr.mozilla.org/mozilla/source/extensions/universalchardet/. |
| 6 |
|
| 7 |
-----------State |
| 8 |
Version 0.2.9 stable. |
| 9 |
Copyright (C) 2011-2019 Alexander Koblov |
| 10 |
The latest version can be found at https://github.com/doublecmd/doublecmd/tree/master/components/chsdet/. |
| 11 |
|
| 12 |
-----------Original |
| 13 |
Based on |
| 14 |
Charset Detector - http://chsdet.sourceforge.net |
| 15 |
Copyright (C) 2006-2013 Nikolaj Yakowlew |
| 16 |
|
| 17 |
-----------Requirements |
| 18 |
Charset Detector doesn't need any external components. |
| 19 |
|
| 20 |
-----------Output |
| 21 |
As result you will get guessed charset as MS Windows Code Page id and charset name. |
| 22 |
|
| 23 |
-----------Licence |
| 24 |
Charset Detector is open source project and distributed under GNU LGPL. |
| 25 |
See the GNU Lesser General Public License for more details - https://opensource.org/licenses/LGPL-2.1 |
| 26 |
|
| 27 |
-----------Supported charsets |
| 28 |
|
| 29 |
+-----------+---------------------------+------------------------+ |
| 30 |
| Code pade | Name | Note | |
| 31 |
+-----------+---------------------------+------------------------+ |
| 32 |
| 0 | ASCII | Pseudo code page. | |
| 33 |
| 855 | IBM855 | | |
| 34 |
| 866 | IBM866 | | |
| 35 |
| 932 | Shift_JIS | | |
| 36 |
| 950 | Big5 | | |
| 37 |
| 1200 | UTF-16LE | | |
| 38 |
| 1201 | UTF-16BE | | |
| 39 |
| 1251 | windows-1251 | | |
| 40 |
| 1252 | windows-1252 | | |
| 41 |
| 1253 | windows-1253 | | |
| 42 |
| 1255 | windows-1255 | | |
| 43 |
| 10007 | x-mac-cyrillic | | |
| 44 |
| 12000 | X-ISO-10646-UCS-4-2143 | | |
| 45 |
| 12000 | UTF-32LE | | |
| 46 |
| 12001 | X-ISO-10646-UCS-4-3412 | | |
| 47 |
| 12001 | UTF-32BE | | |
| 48 |
| 20866 | KOI8-R | | |
| 49 |
| 28595 | ISO-8859-5 | | |
| 50 |
| 28595 | ISO-8859-5 | | |
| 51 |
| 28597 | ISO-8859-7 | | |
| 52 |
| 28598 | ISO-8859-8 | | |
| 53 |
| 50222 | ISO-2022-JP | | |
| 54 |
| 50225 | ISO-2022-KR | | |
| 55 |
| 50227 | ISO-2022-CN | | |
| 56 |
| 51932 | EUC-JP | | |
| 57 |
| 51936 | x-euc-tw | | |
| 58 |
| 51949 | EUC-KR | | |
| 59 |
| 52936 | HZ-GB-2312 | | |
| 60 |
| 54936 | GB18030 | | |
| 61 |
| 65001 | UTF-8 | | |
| 62 |
+-----------+---------------------------+------------------------+ |
| 63 |
|
| 64 |
-----------Types |
| 65 |
Return values |
| 66 |
|
| 67 |
NS_OK = 0; |
| 68 |
NS_ERROR_OUT_OF_MEMORY = $8007000e; |
| 69 |
|
| 70 |
Returned types |
| 71 |
|
| 72 |
rCharsetInfo = record |
| 73 |
Name: PAnsiChar; // Charset GNU canonical name |
| 74 |
CodePage: Integer; // MS Windows CodePage ID |
| 75 |
Language: PAnsiChar; |
| 76 |
end; |
| 77 |
|
| 78 |
-----------Usage sample |
| 79 |
|
| 80 |
Below is a small usage sample in Free Pascal. |
| 81 |
|
| 82 |
function DetectEncoding(const S: String): rCharsetInfo; |
| 83 |
var |
| 84 |
Detector: TnsUniversalDetector; |
| 85 |
begin |
| 86 |
Detector:= TnsUniversalDetector.Create; |
| 87 |
try |
| 88 |
Detector.Reset; |
| 89 |
Detector.HandleData(PAnsiChar(S), Length(S)); |
| 90 |
if not Detector.Done then Detector.DataEnd; |
| 91 |
Result:= Detector.GetDetectedCharsetInfo; |
| 92 |
finally |
| 93 |
FreeAndNil(Detector); |
| 94 |
end; |
| 95 |
end; |