Advertisement
Guest User

Untitled

a guest
Aug 4th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.11 KB | None | 0 0
  1. unit CSVStringList;
  2.  
  3. interface
  4.  
  5. uses
  6.   System.Classes;
  7.  
  8. type
  9.   TCSVStringList = class(TStringList)
  10.   protected
  11.     procedure SetTextStr(const Value: string); override;
  12.   end;
  13.  
  14. implementation
  15.  
  16. uses
  17.   System.SysUtils;
  18.  
  19. { TCSVStringList }
  20.  
  21. procedure TCSVStringList.SetTextStr(const Value: string);
  22. var
  23.   P, Start: PChar;
  24.   S: string;
  25.   LineBreakLen: Integer;
  26.   QuoteFlag: Boolean;
  27. begin
  28.   BeginUpdate;
  29.   try
  30.     Clear;
  31.     P := Pointer(Value);
  32.     if P <> nil then
  33.     begin
  34.       LineBreakLen := Length(LineBreak);
  35.       QuoteFlag := False;
  36.  
  37.       while P^ <> #0 do
  38.       begin
  39.         Start := P;
  40.  
  41.         while P^ <> #0 do
  42.         begin
  43.           if P^ = QuoteChar then
  44.             QuoteFlag := not QuoteFlag
  45.           else
  46.             if not QuoteFlag and (StrLComp(PChar(LineBreak), P, LineBreakLen) = 0) then
  47.               Break;
  48.           Inc(P);
  49.         end;
  50.  
  51.         SetString(S, Start, P - Start);
  52.         Add(S);
  53.         if StrLComp(PChar(LineBreak), P, LineBreakLen) = 0 then
  54.           Inc(P, LineBreakLen);
  55.       end;
  56.     end;
  57.   finally
  58.     EndUpdate;
  59.   end;
  60. end;
  61.  
  62. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement