IdHeaderCoderPlain.pas 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. unit IdHeaderCoderPlain deprecated 'use IIdTextEncoding';
  2. interface
  3. {$i IdCompilerDefines.inc}
  4. uses
  5. IdGlobal, IdHeaderCoderBase;
  6. type
  7. TIdHeaderCoderPlain = class(TIdHeaderCoder)
  8. public
  9. class function Decode(const ACharSet: string; const AData: TIdBytes): String; override;
  10. class function Encode(const ACharSet, AData: String): TIdBytes; override;
  11. class function CanHandle(const ACharSet: String): Boolean; override;
  12. end;
  13. // RLebeau 4/17/10: this forces C++Builder to link to this unit so
  14. // RegisterHeaderCoder can be called correctly at program startup...
  15. {$IFDEF HAS_DIRECTIVE_HPPEMIT_LINKUNIT}
  16. {$HPPEMIT LINKUNIT}
  17. {$ELSE}
  18. {$HPPEMIT '#pragma link "IdHeaderCoderPlain"'}
  19. {$ENDIF}
  20. implementation
  21. uses
  22. SysUtils;
  23. class function TIdHeaderCoderPlain.Decode(const ACharSet: string; const AData: TIdBytes): String;
  24. begin
  25. Result := BytesToStringRaw(AData);
  26. end;
  27. class function TIdHeaderCoderPlain.Encode(const ACharSet, AData: String): TIdBytes;
  28. begin
  29. Result := ToBytes(AData, IndyTextEncoding_8Bit);
  30. end;
  31. class function TIdHeaderCoderPlain.CanHandle(const ACharSet: String): Boolean;
  32. begin
  33. Result := TextStartsWith(ACharSet, 'ISO'); {do not localize}
  34. if Result then begin
  35. // 'ISO-2022-JP' is handled by TIdHeaderCoder2022JP
  36. Result := not TextIsSame(ACharSet, 'ISO-2022-JP'); {do not localize}
  37. Exit;
  38. end;
  39. if not Result then begin
  40. Result := TextStartsWith(ACharSet, 'WINDOWS'); {do not localize}
  41. if not Result then begin
  42. Result := TextStartsWith(ACharSet, 'KOI8'); {do not localize}
  43. if not Result then begin
  44. Result := TextStartsWith(ACharSet, 'GB2312'); {do not localize}
  45. if not Result then begin
  46. Result := TextIsSame(ACharSet, 'US-ASCII');
  47. end;
  48. end;
  49. end;
  50. end;
  51. end;
  52. initialization
  53. RegisterHeaderCoder(TIdHeaderCoderPlain);
  54. finalization
  55. UnregisterHeaderCoder(TIdHeaderCoderPlain);
  56. end.