Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit CSVStringList;
- interface
- uses
- System.Classes;
- type
- TCSVStringList = class(TStringList)
- protected
- procedure SetTextStr(const Value: string); override;
- end;
- implementation
- uses
- System.SysUtils;
- { TCSVStringList }
- procedure TCSVStringList.SetTextStr(const Value: string);
- var
- P, Start: PChar;
- S: string;
- LineBreakLen: Integer;
- QuoteFlag: Boolean;
- begin
- BeginUpdate;
- try
- Clear;
- P := Pointer(Value);
- if P <> nil then
- begin
- LineBreakLen := Length(LineBreak);
- QuoteFlag := False;
- while P^ <> #0 do
- begin
- Start := P;
- while P^ <> #0 do
- begin
- if P^ = QuoteChar then
- QuoteFlag := not QuoteFlag
- else
- if not QuoteFlag and (StrLComp(PChar(LineBreak), P, LineBreakLen) = 0) then
- Break;
- Inc(P);
- end;
- SetString(S, Start, P - Start);
- Add(S);
- if StrLComp(PChar(LineBreak), P, LineBreakLen) = 0 then
- Inc(P, LineBreakLen);
- end;
- end;
- finally
- EndUpdate;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement