Delphi 7 compatibility fix : handle "TStringList.StrictDelimiter" + test
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3356 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
ba37ace85f
commit
38bb8b4756
@ -63,7 +63,10 @@ Type
|
||||
function LoadBufferFromFile(const AFileName : string) : TByteDynArray;
|
||||
function LoadBufferFromStream(AStream : TStream) : TByteDynArray;
|
||||
|
||||
|
||||
{$IFNDEF WST_HAS_STRICT_DELIMITER}
|
||||
procedure SetListData(AList : TStringList; const AText : string);
|
||||
{$ENDIF WST_HAS_STRICT_DELIMITER}
|
||||
|
||||
implementation
|
||||
|
||||
function IsStrEmpty(Const AStr:String):Boolean;
|
||||
@ -256,6 +259,33 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
{$IFNDEF WST_HAS_STRICT_DELIMITER}
|
||||
procedure SetListData(AList : TStringList; const AText : string);
|
||||
var
|
||||
i, oldPos, c : Integer;
|
||||
s : string;
|
||||
begin
|
||||
c := Length(AText);
|
||||
oldPos := 1;
|
||||
s := '';
|
||||
i := 1;
|
||||
while (i <= c) do begin
|
||||
if (AText[i] = PROP_LIST_DELIMITER) then begin
|
||||
s := Copy(AText,oldPos,(i-oldPos));
|
||||
if (s <> '') then
|
||||
AList.Add(s);
|
||||
oldPos := i+1;
|
||||
end;
|
||||
i := i+1;
|
||||
end;
|
||||
if (i > oldPos) then begin
|
||||
s := Copy(AText,oldPos,(i-oldPos));
|
||||
if (s <> '') then
|
||||
AList.Add(s);
|
||||
end;
|
||||
end;
|
||||
{$ENDIF WST_HAS_STRICT_DELIMITER}
|
||||
|
||||
procedure TPublishedPropertyManager.SetProperties(const APropsStr: string);
|
||||
var
|
||||
lst : TStringList;
|
||||
@ -265,10 +295,14 @@ begin
|
||||
Exit;
|
||||
lst := TStringList.Create();
|
||||
Try
|
||||
{$IFDEF WST_HAS_STRICT_DELIMITER}
|
||||
lst.QuoteChar := #0;
|
||||
lst.Delimiter := PROP_LIST_DELIMITER;
|
||||
lst.StrictDelimiter := True;
|
||||
lst.DelimitedText := APropsStr;
|
||||
{$ELSE WST_HAS_STRICT_DELIMITER}
|
||||
SetListData(lst,APropsStr);
|
||||
{$ENDIF WST_HAS_STRICT_DELIMITER}
|
||||
for i := 0 to Pred(lst.Count) do
|
||||
SetProperty(lst.Names[i],lst.Values[lst.Names[i]]);
|
||||
Finally
|
||||
|
@ -23,7 +23,7 @@ uses
|
||||
{$ENDIF}
|
||||
TypInfo,
|
||||
base_service_intf, server_service_intf,
|
||||
library_imp_utils, parserutils;
|
||||
library_imp_utils, parserutils, imp_utils;
|
||||
|
||||
type
|
||||
|
||||
@ -135,6 +135,9 @@ type
|
||||
TTest_Procs = class(TTestCase)
|
||||
published
|
||||
procedure test_GetToken();
|
||||
{$IFNDEF WST_HAS_STRICT_DELIMITER}
|
||||
procedure test_SetListData();
|
||||
{$ENDIF WST_HAS_STRICT_DELIMITER}
|
||||
end;
|
||||
|
||||
implementation
|
||||
@ -923,6 +926,27 @@ begin
|
||||
do_tests('#<#');
|
||||
end;
|
||||
|
||||
{$IFNDEF WST_HAS_STRICT_DELIMITER}
|
||||
procedure TTest_Procs.test_SetListData();
|
||||
var
|
||||
ls : TStringList;
|
||||
begin
|
||||
ls := TStringList.Create();
|
||||
try
|
||||
SetListData(ls,'item1=azerty;item2=http: 123;item3=a b c');
|
||||
CheckEquals(3,ls.Count,'Items count');
|
||||
CheckEquals('item1',ls.Names[0]);
|
||||
CheckEquals('azerty',ls.ValueFromIndex[0]);
|
||||
CheckEquals('item2',ls.Names[1]);
|
||||
CheckEquals('http: 123',ls.ValueFromIndex[1]);
|
||||
CheckEquals('item3',ls.Names[2]);
|
||||
CheckEquals('a b c',ls.ValueFromIndex[2]);
|
||||
finally
|
||||
ls.Free();
|
||||
end;
|
||||
end;
|
||||
{$ENDIF WST_HAS_STRICT_DELIMITER}
|
||||
|
||||
initialization
|
||||
ListToRelease := TInterfaceList.Create();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user