Difference between revisions of "isUnicode/de"
From Free Pascal wiki
Jump to navigationJump to searchm |
m (Fixed syntax highlighting; deleted category included in page template) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{isUnicode}} | {{isUnicode}} | ||
− | + | ||
− | + | ||
− | Das Unterprogramm prüft, unabhängig vom zugrunde liegenden Betriebssystem, ob es sich um eine Unicode-Datei handelt. | + | Zurück zur Seite [[code examples/de|Code Beispiele]]. |
− | Das Unterprogramm ist nur dann erfolgreich, wenn die Unicode-Datei eine BOM (Byte-Order-Markierung) hat. | + | |
− | Unicode-Dateien ohne eine BOM können nicht zweifelsfrei als Unicode-Dateien identifiziert werden. | + | |
− | + | Das Unterprogramm prüft, unabhängig vom zugrunde liegenden Betriebssystem, ob es sich um eine Unicode-Datei handelt. | |
− | <syntaxhighlight> | + | |
+ | Das Unterprogramm ist nur dann erfolgreich, wenn die Unicode-Datei eine BOM (Byte-Order-Markierung) hat. | ||
+ | |||
+ | Unicode-Dateien ohne eine BOM können nicht zweifelsfrei als Unicode-Dateien identifiziert werden. | ||
+ | |||
+ | |||
+ | <syntaxhighlight lang=pascal> | ||
uses | uses | ||
FileUtil, ...; | FileUtil, ...; | ||
Line 89: | Line 95: | ||
<br> | <br> | ||
Aufruf unter Windows: | Aufruf unter Windows: | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
... | ... | ||
Line 101: | Line 107: | ||
<br> | <br> | ||
Aufruf unter Linux: | Aufruf unter Linux: | ||
− | <syntaxhighlight> | + | <syntaxhighlight lang=pascal> |
... | ... | ||
Line 111: | Line 117: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | |||
− | |||
− | |||
− |
Latest revision as of 07:12, 18 February 2020
│
Deutsch (de) │
Zurück zur Seite Code Beispiele.
Das Unterprogramm prüft, unabhängig vom zugrunde liegenden Betriebssystem, ob es sich um eine Unicode-Datei handelt.
Das Unterprogramm ist nur dann erfolgreich, wenn die Unicode-Datei eine BOM (Byte-Order-Markierung) hat.
Unicode-Dateien ohne eine BOM können nicht zweifelsfrei als Unicode-Dateien identifiziert werden.
uses
FileUtil, ...;
...
const
conNoUnicode = 0;
conUTF1 = 1;
conUTF7 = 2;
conUTF8 = 3;
conUTF16BigEndian = 4;
conUTF16LittleEndian = 5;
conUTF32BigEndian = 6;
conUTF32LittleEndian = 7;
conUTFEBCDIC = 8; // Format auf IBM-Großrechnern
conSCSU = 9; // Standard Compression Scheme for Unicode
conBOCU1 = 10; // Binary Ordered Compression for Unicode
conGB18030 = 11; // chinesische Zeichenkodierungsstandard (GB 18030)
...
function IsUnicode(const conStrQuellDateiname: string): integer;
var
txtQuelldatei: file of char;
chrZeichen: char;
intI: integer = 0;
strBOM: string = '';
begin
Result := conNoUnicode;
AssignFile(txtQuelldatei, UTF8ToSys(conStrQuellDateiname));
Reset(txtQuelldatei);
// Prüft auf Dateiende und liest die Zeichen für die BOM ein
while not EOF(txtQuelldatei) or (intI < 5) do
begin
intI := intI + 1;
Read(txtQuelldatei, chrZeichen);
strBOM := strBOM + chrZeichen;
end;
closefile(txtQuelldatei);
if Copy(strBOM, 1, 3) = #$F7#$64#$4C then
Result := conUTF1
else if Copy(strBOM, 1, 4) = #$2B#$2F#$76#$38 then
Result := conUTF7
else if Copy(strBOM, 1, 4) = #$2B#$2F#$76#$39 then
Result := conUTF7
else if Copy(strBOM, 1, 4) = #$2B#$2F#$76#$2B then
Result := conUTF7
else if Copy(strBOM, 1, 4) = #$2B#$2F#$76#$2F then
Result := conUTF7
else if Copy(strBOM, 1, 3) = #$EF#$BB#$BF then
Result := conUTF8
else if Copy(strBOM, 1, 2) = #$FE#$FF then
Result := conUTF16BigEndian
else if Copy(strBOM, 1, 2) = #$FF#$FE then
Result := conUTF16LittleEndian
else if strBOM = #$00#$00#$FE#$FF then
Result := conUTF32BigEndian
else if strBOM = #$FF#$FE#$00#$00 then
Result := conUTF32LittleEndian
else if strBOM = #$DD#$73#$66#$73 then
Result := conUTFEBCDIC
else if Copy(strBOM, 1, 3) = #$0E#$FE#$FF then
Result := conSCSU
else if Copy(strBOM, 1, 3) = #$FB#$EE#$28 then
Result := conBOCU1
else if strBOM = #$FB#$EE#$28#$FF then
Result := conBOCU1
else if strBOM = #$84#$31#$59#$33 then
Result := conGB18030
else
Result := conNoUnicode;
end;
Aufruf unter Windows:
...
case IsUnicode('E:\Test.txt') of
...
...
Aufruf unter Linux:
...
case IsUnicode('/home/user/Test.txt') of
...
...