UnsignedFunc.pas 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. unit UnsignedFunc;
  2. {
  3. Inno Setup
  4. Copyright (C) 1997-2025 Jordan Russell
  5. Portions by Martijn Laan
  6. For conditions of distribution and use, see LICENSE.TXT.
  7. Provides unsigned alternatives to Delphi functions that use signed types for parameters or return
  8. values where unsigned types would have been more appropriate
  9. }
  10. interface
  11. uses
  12. SysUtils;
  13. function ULength(const S: String): Cardinal; overload; inline;
  14. function ULength(const S: RawByteString): Cardinal; overload; inline;
  15. function ULength(const S: WideString): Cardinal; overload; inline;
  16. function ULength(const S: TBytes): Cardinal; overload; inline;
  17. procedure UMove(const Source; var Dest; Count: NativeUInt);
  18. implementation
  19. function ULength(const S: String): Cardinal;
  20. begin
  21. Result := Cardinal(Length(S));
  22. end;
  23. function ULength(const S: RawByteString): Cardinal;
  24. begin
  25. Result := Cardinal(Length(S));
  26. end;
  27. function ULength(const S: WideString): Cardinal;
  28. begin
  29. Result := Cardinal(Length(S));
  30. end;
  31. function ULength(const S: TBytes): Cardinal;
  32. begin
  33. Result := Cardinal(Length(S));
  34. end;
  35. procedure UMove(const Source; var Dest; Count: NativeUInt);
  36. begin
  37. var SourceBuf: PByte := @Source;
  38. var DestBuf: PByte := @Dest;
  39. while Count > 0 do begin
  40. var MoveCount := High(NativeInt);
  41. if Count < NativeUInt(MoveCount) then
  42. MoveCount := NativeInt(Count);
  43. Move(SourceBuf^, DestBuf^, MoveCount);
  44. Dec(Count, MoveCount);
  45. Inc(SourceBuf, MoveCount);
  46. Inc(DestBuf, MoveCount);
  47. end;
  48. end;
  49. end.