isUnicode/de: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: isUnicode/de
| Old | New | Line | |
|---|---|---|---|
| 1 | + | Zurück zur Seite [[code examples/de|Code Beispiele]]. | |
| 2 | + | ||
| 3 | + | Das Unterprogramm prüft, unabhängig vom zugrunde liegenden Betriebssystem, ob es sich um eine Unicode-Datei handelt. | |
| 4 | + | ||
| 5 | + | Das Unterprogramm ist nur dann erfolgreich, wenn die Unicode-Datei eine BOM (Byte-Order-Markierung) hat. | |
| 6 | + | ||
| 7 | + | Unicode-Dateien ohne eine BOM können nicht zweifelsfrei als Unicode-Dateien identifiziert werden. | |
| 8 | + | ||
| 9 | + | ``` pascal | |
| 10 | + | uses | |
| 11 | + | FileUtil, ...; | |
| 12 | + | ||
| 13 | + | ... | |
| 14 | + | ||
| 15 | + | const | |
| 16 | + | conNoUnicode = 0; | |
| 17 | + | conUTF1 = 1; | |
| 18 | + | conUTF7 = 2; | |
| 19 | + | conUTF8 = 3; | |
| 20 | + | conUTF16BigEndian = 4; | |
| 21 | + | conUTF16LittleEndian = 5; | |
| 22 | + | conUTF32BigEndian = 6; | |
| 23 | + | conUTF32LittleEndian = 7; | |
| 24 | + | conUTFEBCDIC = 8; // Format auf IBM-Großrechnern | |
| 25 | + | conSCSU = 9; // Standard Compression Scheme for Unicode | |
| 26 | + | conBOCU1 = 10; // Binary Ordered Compression for Unicode | |
| 27 | + | conGB18030 = 11; // chinesische Zeichenkodierungsstandard (GB 18030) | |
| 28 | + | ||
| 29 | + | ... | |
| 30 | + | ||
| 31 | + | function IsUnicode(const conStrQuellDateiname: string): integer; | |
| 32 | + | var | |
| 33 | + | txtQuelldatei: file of char; | |
| 34 | + | chrZeichen: char; | |
| 35 | + | intI: integer = 0; | |
| 36 | + | strBOM: string = ''; | |
| 37 | + | ||
| 38 | + | begin | |
| 39 | + | ||
| 40 | + | Result := conNoUnicode; | |
| 41 | + | ||
| 42 | + | AssignFile(txtQuelldatei, UTF8ToSys(conStrQuellDateiname)); | |
| 43 | + | Reset(txtQuelldatei); | |
| 44 | + | ||
| 45 | + | // Prüft auf Dateiende und liest die Zeichen für die BOM ein | |
| 46 | + | while not EOF(txtQuelldatei) or (intI < 5) do | |
| 47 | + | begin | |
| 48 | + | intI := intI + 1; | |
| 49 | + | Read(txtQuelldatei, chrZeichen); | |
| 50 | + | strBOM := strBOM + chrZeichen; | |
| 51 | + | end; | |
| 52 | + | ||
| 53 | + | closefile(txtQuelldatei); | |
| 54 | + | ||
| 55 | + | if Copy(strBOM, 1, 3) = #$F7#$64#$4C then | |
| 56 | + | Result := conUTF1 | |
| 57 | + | else if Copy(strBOM, 1, 4) = #$2B#$2F#$76#$38 then | |
| 58 | + | Result := conUTF7 | |
| 59 | + | else if Copy(strBOM, 1, 4) = #$2B#$2F#$76#$39 then | |
| 60 | + | Result := conUTF7 | |
| 61 | + | else if Copy(strBOM, 1, 4) = #$2B#$2F#$76#$2B then | |
| 62 | + | Result := conUTF7 | |
| 63 | + | else if Copy(strBOM, 1, 4) = #$2B#$2F#$76#$2F then | |
| 64 | + | Result := conUTF7 | |
| 65 | + | else if Copy(strBOM, 1, 3) = #$EF#$BB#$BF then | |
| 66 | + | Result := conUTF8 | |
| 67 | + | else if Copy(strBOM, 1, 2) = #$FE#$FF then | |
| 68 | + | Result := conUTF16BigEndian | |
| 69 | + | else if Copy(strBOM, 1, 2) = #$FF#$FE then | |
| 70 | + | Result := conUTF16LittleEndian | |
| 71 | + | else if strBOM = #$00#$00#$FE#$FF then | |
| 72 | + | Result := conUTF32BigEndian | |
| 73 | + | else if strBOM = #$FF#$FE#$00#$00 then | |
| 74 | + | Result := conUTF32LittleEndian | |
| 75 | + | else if strBOM = #$DD#$73#$66#$73 then | |
| 76 | + | Result := conUTFEBCDIC | |
| 77 | + | else if Copy(strBOM, 1, 3) = #$0E#$FE#$FF then | |
| 78 | + | Result := conSCSU | |
| 79 | + | else if Copy(strBOM, 1, 3) = #$FB#$EE#$28 then | |
| 80 | + | Result := conBOCU1 | |
| 81 | + | else if strBOM = #$FB#$EE#$28#$FF then | |
| 82 | + | Result := conBOCU1 | |
| 83 | + | else if strBOM = #$84#$31#$59#$33 then | |
| 84 | + | Result := conGB18030 | |
| 85 | + | else | |
| 86 | + | Result := conNoUnicode; | |
| 87 | + | ||
| 88 | + | end; | |
| 89 | + | ``` | |
| 90 | + | ||
| 91 | + | Aufruf unter Windows: | |
| 92 | + | ||
| 93 | + | ``` pascal | |
| 94 | + | ||
| 95 | + | ... | |
| 96 | + | ||
| 97 | + | case IsUnicode('E:\Test.txt') of | |
| 98 | + | ... | |
| 99 | + | ||
| 100 | + | ... | |
| 101 | + | ``` | |
| 102 | + | ||
| 103 | + | Aufruf unter Linux: | |
| 104 | + | ||
| 105 | + | ``` pascal | |
| 106 | + | ||
| 107 | + | ... | |
| 108 | + | ||
| 109 | + | case IsUnicode('/home/user/Test.txt') of | |
| 110 | + | ... | |
| 111 | + | ||
| 112 | + | ... | |
| 113 | + | ``` | |
| 114 | + | ||
| 115 | + | --- | |
| 116 | + | *From the Free Pascal wiki, page "isUnicode/de", as it stood on 2020-02-18 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
