Difference between revisions of "isUnicode/de"

From Lazarus wiki
Jump to navigationJump to search
m
m (Fixed syntax highlighting; deleted category included in page template)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 
{{isUnicode}}
 
{{isUnicode}}
<br>
+
 
Zurück zur Seite [[code examples/de|Code Beispiele]].<br>
+
 
<br>
+
Zurück zur Seite [[code examples/de|Code Beispiele]].
Das Unterprogramm prüft, unabhängig vom zugrunde liegenden Betriebssystem, ob es sich um eine Unicode-Datei handelt.<br>
+
 
Das Unterprogramm ist nur dann erfolgreich, wenn die Unicode-Datei eine BOM (Byte-Order-Markierung) hat.<br>
+
 
Unicode-Dateien ohne eine BOM können nicht zweifelsfrei als Unicode-Dateien identifiziert werden.<br>
+
Das Unterprogramm prüft, unabhängig vom zugrunde liegenden Betriebssystem, ob es sich um eine Unicode-Datei handelt.
<br>
+
 
<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 90: Line 95:
 
<br>
 
<br>
 
Aufruf unter Windows:
 
Aufruf unter Windows:
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
  
 
   ...
 
   ...
Line 102: Line 107:
 
<br>
 
<br>
 
Aufruf unter Linux:
 
Aufruf unter Linux:
<syntaxhighlight>
+
<syntaxhighlight lang=pascal>
  
 
   ...
 
   ...
Line 112: Line 117:
  
 
</syntaxhighlight>
 
</syntaxhighlight>
<br>
 
<br>
 
--[[User:Olaf|Olaf]] 07:50, 29 August 2013 (CEST)
 
[[Category:Code Parts/de]]{{AutoCategory}}
 

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
    ...

  ...