|
@@ -504,12 +504,24 @@ end;
|
|
|
|
|
|
Procedure TStrings.SetDelimitedText(const AValue: string);
|
|
Procedure TStrings.SetDelimitedText(const AValue: string);
|
|
|
|
|
|
|
|
+begin
|
|
|
|
+ CheckSpecialChars;
|
|
|
|
+ DoSetDelimitedText(aValue,True,FStrictDelimiter,FQuoteChar,FDelimiter);
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+Procedure TStrings.DoSetDelimitedText(const AValue: string; DoClear,aStrictDelimiter : Boolean; aQuoteChar,aDelimiter : Char);
|
|
|
|
+
|
|
var
|
|
var
|
|
len,i,j: SizeInt;
|
|
len,i,j: SizeInt;
|
|
aNotFirst:boolean;
|
|
aNotFirst:boolean;
|
|
|
|
|
|
|
|
+ Procedure AddQuoted;
|
|
|
|
+
|
|
|
|
+ begin
|
|
|
|
+ Add(StringReplace(Copy(AValue,i+1,j-i-1),aQuoteChar+aQuoteChar,aQuoteChar, [rfReplaceAll]));
|
|
|
|
+ end;
|
|
|
|
+
|
|
begin
|
|
begin
|
|
- CheckSpecialChars;
|
|
|
|
BeginUpdate;
|
|
BeginUpdate;
|
|
|
|
|
|
i:=1;
|
|
i:=1;
|
|
@@ -524,40 +536,40 @@ begin
|
|
try
|
|
try
|
|
Clear;
|
|
Clear;
|
|
len:=length(AValue);
|
|
len:=length(AValue);
|
|
- If StrictDelimiter then
|
|
|
|
|
|
+ If aStrictDelimiter then
|
|
begin
|
|
begin
|
|
while i<=Len do begin
|
|
while i<=Len do begin
|
|
// skip delimiter
|
|
// skip delimiter
|
|
- if aNotFirst and (i<=len) and (AValue[i]=FDelimiter) then
|
|
|
|
|
|
+ if aNotFirst and (i<=len) and (AValue[i]=aDelimiter) then
|
|
inc(i);
|
|
inc(i);
|
|
|
|
|
|
// read next string
|
|
// read next string
|
|
if i<=len then begin
|
|
if i<=len then begin
|
|
- if AValue[i]=FQuoteChar then begin
|
|
|
|
|
|
+ if AValue[i]=aQuoteChar then begin
|
|
// next string is quoted
|
|
// next string is quoted
|
|
j:=i+1;
|
|
j:=i+1;
|
|
while (j<=len) and
|
|
while (j<=len) and
|
|
- ( (AValue[j]<>FQuoteChar) or
|
|
|
|
- ( (j+1<=len) and (AValue[j+1]=FQuoteChar) ) ) do begin
|
|
|
|
- if (j<=len) and (AValue[j]=FQuoteChar) then inc(j,2)
|
|
|
|
- else inc(j);
|
|
|
|
- end;
|
|
|
|
- // j is position of closing quote
|
|
|
|
- Add( StringReplace (Copy(AValue,i+1,j-i-1),
|
|
|
|
- FQuoteChar+FQuoteChar,FQuoteChar, [rfReplaceAll]));
|
|
|
|
|
|
+ ((AValue[j]<>aQuoteChar) or
|
|
|
|
+ ((j+1<=len) and (AValue[j+1]=aQuoteChar))) do
|
|
|
|
+ begin
|
|
|
|
+ if (j<=len) and (AValue[j]=aQuoteChar) then
|
|
|
|
+ inc(j,2)
|
|
|
|
+ else
|
|
|
|
+ inc(j);
|
|
|
|
+ end;
|
|
|
|
+ AddQuoted;
|
|
i:=j+1;
|
|
i:=j+1;
|
|
end else begin
|
|
end else begin
|
|
// next string is not quoted; read until delimiter
|
|
// next string is not quoted; read until delimiter
|
|
j:=i;
|
|
j:=i;
|
|
while (j<=len) and
|
|
while (j<=len) and
|
|
- (AValue[j]<>FDelimiter) do inc(j);
|
|
|
|
|
|
+ (AValue[j]<>aDelimiter) do inc(j);
|
|
Add( Copy(AValue,i,j-i));
|
|
Add( Copy(AValue,i,j-i));
|
|
i:=j;
|
|
i:=j;
|
|
end;
|
|
end;
|
|
end else begin
|
|
end else begin
|
|
if aNotFirst then Add('');
|
|
if aNotFirst then Add('');
|
|
end;
|
|
end;
|
|
-
|
|
|
|
aNotFirst:=true;
|
|
aNotFirst:=true;
|
|
end;
|
|
end;
|
|
end
|
|
end
|
|
@@ -565,32 +577,30 @@ begin
|
|
begin
|
|
begin
|
|
while i<=len do begin
|
|
while i<=len do begin
|
|
// skip delimiter
|
|
// skip delimiter
|
|
- if aNotFirst and (i<=len) and (AValue[i]=FDelimiter) then inc(i);
|
|
|
|
|
|
+ if aNotFirst and (i<=len) and (AValue[i]=aDelimiter) then inc(i);
|
|
|
|
|
|
// skip spaces
|
|
// skip spaces
|
|
while (i<=len) and (Ord(AValue[i])<=Ord(' ')) do inc(i);
|
|
while (i<=len) and (Ord(AValue[i])<=Ord(' ')) do inc(i);
|
|
|
|
|
|
// read next string
|
|
// read next string
|
|
if i<=len then begin
|
|
if i<=len then begin
|
|
- if AValue[i]=FQuoteChar then begin
|
|
|
|
|
|
+ if AValue[i]=aQuoteChar then begin
|
|
// next string is quoted
|
|
// next string is quoted
|
|
j:=i+1;
|
|
j:=i+1;
|
|
while (j<=len) and
|
|
while (j<=len) and
|
|
- ( (AValue[j]<>FQuoteChar) or
|
|
|
|
- ( (j+1<=len) and (AValue[j+1]=FQuoteChar) ) ) do begin
|
|
|
|
- if (j<=len) and (AValue[j]=FQuoteChar) then inc(j,2)
|
|
|
|
|
|
+ ( (AValue[j]<>aQuoteChar) or
|
|
|
|
+ ( (j+1<=len) and (AValue[j+1]=aQuoteChar) ) ) do begin
|
|
|
|
+ if (j<=len) and (AValue[j]=aQuoteChar) then inc(j,2)
|
|
else inc(j);
|
|
else inc(j);
|
|
end;
|
|
end;
|
|
- // j is position of closing quote
|
|
|
|
- Add( StringReplace (Copy(AValue,i+1,j-i-1),
|
|
|
|
- FQuoteChar+FQuoteChar,FQuoteChar, [rfReplaceAll]));
|
|
|
|
|
|
+ AddQuoted;
|
|
i:=j+1;
|
|
i:=j+1;
|
|
end else begin
|
|
end else begin
|
|
// next string is not quoted; read until control character/space/delimiter
|
|
// next string is not quoted; read until control character/space/delimiter
|
|
j:=i;
|
|
j:=i;
|
|
while (j<=len) and
|
|
while (j<=len) and
|
|
(Ord(AValue[j])>Ord(' ')) and
|
|
(Ord(AValue[j])>Ord(' ')) and
|
|
- (AValue[j]<>FDelimiter) do inc(j);
|
|
|
|
|
|
+ (AValue[j]<>aDelimiter) do inc(j);
|
|
Add( Copy(AValue,i,j-i));
|
|
Add( Copy(AValue,i,j-i));
|
|
i:=j;
|
|
i:=j;
|
|
end;
|
|
end;
|
|
@@ -944,25 +954,17 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TStrings.AddDelimitedText(const S: String; ADelimiter: Char;
|
|
|
|
- AStrictDelimiter: Boolean);
|
|
|
|
-var
|
|
|
|
- L: TStringList;
|
|
|
|
|
|
+procedure TStrings.AddDelimitedText(const S: String; ADelimiter: Char; AStrictDelimiter: Boolean);
|
|
|
|
+
|
|
begin
|
|
begin
|
|
- L := TStringList.Create;
|
|
|
|
- try
|
|
|
|
- L.Delimiter := ADelimiter;
|
|
|
|
- L.StrictDelimiter := AStrictDelimiter;
|
|
|
|
- L.DelimitedText := S;
|
|
|
|
- AddStrings(L);
|
|
|
|
- finally
|
|
|
|
- L.Free;
|
|
|
|
- end;
|
|
|
|
|
|
+ CheckSpecialChars;
|
|
|
|
+ DoSetDelimitedText(S,False,AStrictDelimiter,FQuoteChar,ADelimiter);
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TStrings.AddDelimitedText(const S: String);
|
|
procedure TStrings.AddDelimitedText(const S: String);
|
|
begin
|
|
begin
|
|
- AddDelimitedText(S, FDelimiter, FStrictDelimiter);
|
|
|
|
|
|
+ CheckSpecialChars;
|
|
|
|
+ DoSetDelimitedText(S,False,FStrictDelimiter,FQuoteChar,FDelimiter);
|
|
end;
|
|
end;
|
|
|
|
|
|
Procedure TStrings.SetUpdateState(Updating: Boolean);
|
|
Procedure TStrings.SetUpdateState(Updating: Boolean);
|