Einzelnen Beitrag anzeigen

mjustin

Registriert seit: 14. Apr 2008
3.004 Beiträge
 
Delphi 2009 Professional
 
#1

Verwenden der LazUTF8 Unit verändert Ergebnis von TIdURI.URLDecode

  Alt 11. Feb 2019, 14:42
Test 1: Free Pascal 3.0.4 Programm ohne Unit LazUTF8:

Delphi-Quellcode:
program FPCTest;

uses IdURI;

begin
  WriteLn(TIdURI.URLDecode('%C3%84%C3%96%C3%9C'));
  ReadLn;
end.
Ausgabe: ÄÖÜ

Test 2: wie Test 1, aber mit Unit LazUTF8 (für UTF-8 Unterstützung, hier beschrieben)

Delphi-Quellcode:
program FPCTest;

uses IdURI, LazUTF8;

begin
  WriteLn(TIdURI.URLDecode('%C3%84%C3%96%C3%9C'));
  ReadLn;
end.
Ausgabe: ???

Man kann zwar TIdURI.URLDecode direkt im Indy Sourcecode anpassen, in etwa so:


Delphi-Quellcode:
  {$IFDEF FPC}
  Result := string(AByteEncoding.GetString(LBytes));
  {$ELSE}
  {$IFDEF STRING_IS_ANSI}
  EnsureEncoding(ADestEncoding, encOSDefault);
  CheckByteEncoding(LBytes, AByteEncoding, ADestEncoding);
  SetString(Result, PAnsiChar(LBytes), Length(LBytes));
  {$ELSE}
  Result := AByteEncoding.GetString(LBytes);
  {$ENDIF}
  {$ENDIF}
- aber dabei ist es nicht möglich, anhand eines Flags zu "erkennen" ob der Code mit oder ohne der Unit LazUTF8 kompiliert wird.

Relativ naheliegend wäre ein eigenes Symbol zu definieren:

Delphi-Quellcode:
  {$IFDEF USES_LAZUTF8}
  Result := string(AByteEncoding.GetString(LBytes));
  {$ELSE}
  {$IFDEF STRING_IS_ANSI}
  EnsureEncoding(ADestEncoding, encOSDefault);
  CheckByteEncoding(LBytes, AByteEncoding, ADestEncoding);
  SetString(Result, PAnsiChar(LBytes), Length(LBytes));
  {$ELSE}
  Result := AByteEncoding.GetString(LBytes);
  {$ENDIF}
  {$ENDIF}

Oder habe ich noch eine Möglichkeit übersehen, mit der man das Ändern des Indy-Quelltext vermeiden könnte?
Michael Justin
  Mit Zitat antworten Zitat