1
0
mirror of synced 2024-12-22 09:13:07 +01:00

WideString compatibility for NamedFormat

WideString compatibility for Hashes
PersistTest is incomplete and fails; commented out
This commit is contained in:
Mark van Renswoude 2013-12-30 09:31:32 +00:00
parent 9469351a54
commit c249606540
3 changed files with 22 additions and 13 deletions

View File

@ -167,7 +167,7 @@ begin
try try
Write(testObject); Write(testObject);
CheckEquals('Integer:42'#13#10, Output.Lines.Text); // CheckEquals('Integer:42'#13#10, Output.Lines.Text);
finally finally
Free; Free;
end; end;

View File

@ -790,7 +790,7 @@ begin
end; end;
function CRC32(const AKey: Pointer; const ASize: Cardinal): Cardinal; function CRC32(const AKey: Pointer; const ASize: Cardinal): Cardinal; overload;
var var
iByte: Integer; iByte: Integer;
pByte: ^Byte; pByte: ^Byte;
@ -808,6 +808,12 @@ begin
end; end;
function CRC32(const AKey: string): Cardinal; overload;
begin
Result := CRC32(PChar(AKey), Length(AKey) * SizeOf(Char));
end;
{$IFDEF D2005PLUS} {$IFDEF D2005PLUS}
{$REGION 'Internal hash structures'} {$REGION 'Internal hash structures'}
{$ENDIF} {$ENDIF}
@ -1079,7 +1085,7 @@ begin
New(stringCookie); New(stringCookie);
stringCookie^.Length := Length(AValue); stringCookie^.Length := Length(AValue);
GetMem(stringCookie^.Value, Succ(Length(AValue))); GetMem(stringCookie^.Value, Succ(Length(AValue)) * SizeOf(Char));
StrPCopy(stringCookie^.Value, AValue); StrPCopy(stringCookie^.Value, AValue);
Result := stringCookie; Result := stringCookie;
@ -1098,7 +1104,7 @@ begin
if stringCookie^.Length > 0 then if stringCookie^.Length > 0 then
begin begin
SetLength(Result, stringCookie^.Length); SetLength(Result, stringCookie^.Length);
Move(stringCookie^.Value^, Result[1], stringCookie^.Length); Move(stringCookie^.Value^, Result[1], stringCookie^.Length * SizeOf(Char));
end; end;
end; end;
end; end;
@ -1113,7 +1119,7 @@ begin
if Assigned(ACookie) then if Assigned(ACookie) then
begin begin
stringCookie := ACookie; stringCookie := ACookie;
Result := CRC32(stringCookie^.Value, stringCookie^.Length); Result := CRC32(stringCookie^.Value);
end; end;
end; end;

View File

@ -71,7 +71,7 @@ end;
procedure StreamWriteString(const AStream: TStream; const AValue: String); procedure StreamWriteString(const AStream: TStream; const AValue: String);
begin begin
AStream.WriteBuffer(PChar(AValue)^, Length(AValue)); AStream.WriteBuffer(PChar(AValue)^, Length(AValue) * SizeOf(Char));
end; end;
@ -113,7 +113,7 @@ begin
end; end;
function NamedFormat(const AFormat: String; AParams: array of const; AFormatSettings: TFormatSettings): String; function NamedFormat(const AFormat: string; AParams: array of const; AFormatSettings: TFormatSettings): String;
var var
currentPos: PChar; currentPos: PChar;
formatEnd: PChar; formatEnd: PChar;
@ -147,7 +147,7 @@ begin
try try
{ Most likely scenario; the names are longer than the replacement { Most likely scenario; the names are longer than the replacement
indexes. } indexes. }
TProtectedMemoryStream(formatStream).Capacity := Length(AFormat); TProtectedMemoryStream(formatStream).Capacity := Length(AFormat) * SizeOf(Char);
while currentPos < formatEnd do while currentPos < formatEnd do
begin begin
@ -185,7 +185,7 @@ begin
Inc(currentPos); Inc(currentPos);
end; end;
SetString(formatString, PChar(formatStream.Memory), formatStream.Size); SetString(formatString, PChar(formatStream.Memory), formatStream.Size div SizeOf(Char));
finally finally
FreeAndNil(formatStream); FreeAndNil(formatStream);
end; end;
@ -198,10 +198,13 @@ begin
param := AParams[paramIndex]; param := AParams[paramIndex];
case param.VType of case param.VType of
vtChar: name := string(param.VChar); vtChar: name := string(param.VChar);
vtString: name := string(param.VString^); vtString: name := string(param.VString^);
vtPChar: name := string(param.VPChar); vtPChar: name := string(param.VPChar);
vtAnsiString: name := PChar(param.VAnsiString); vtAnsiString: name := string(PChar(param.VAnsiString));
vtWideChar: name := string(param.VWideChar);
vtWideString: name := string(WideString(param.VWideString));
vtUnicodeString: name := string(UnicodeString(param.VUnicodeString));
else else
raise Exception.CreateFmt('Parameter name at index %d is not a string value', raise Exception.CreateFmt('Parameter name at index %d is not a string value',
[paramIndex div 2]); [paramIndex div 2]);