Changeset 91 for trunk/UContact.pas


Ignore:
Timestamp:
Feb 2, 2022, 4:33:25 PM (2 years ago)
Author:
chronos
Message:
  • Added: A windows for showing log output for selected test case.
  • Added: Various load-save tests.
  • Modified: Improved parsing vCard format.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UContact.pas

    r90 r91  
    141141    class destructor Destroy2;
    142142    procedure SaveToStrings(Output: TStrings);
    143     function LoadFromStrings(Lines: TStrings; StartLine: Integer = 0): Integer;
     143    function LoadFromStrings(Lines: TStrings; var StartLine: Integer): Boolean;
    144144    procedure SaveToFile(FileName: string);
    145145    procedure LoadFromFile(FileName: string);
     
    11341134            end;
    11351135          end;
    1136           if LinePrefix <> '' then Add('');
    11371136        end;
    11381137      end;
     
    11411140end;
    11421141
    1143 function TContact.LoadFromStrings(Lines: TStrings; StartLine: Integer = 0): Integer;
     1142function TContact.LoadFromStrings(Lines: TStrings; var StartLine: Integer): Boolean;
    11441143type
    11451144  TParseState = (psNone, psInside, psFinished);
     
    11541153  Names: string;
    11551154begin
     1155  Result := False;
    11561156  ParseState := psNone;
    11571157  I := StartLine;
     
    11661166      end else begin
    11671167        ContactsFile.Error(SExpectedVCardBegin, I + 1);
    1168         I := -1;
    11691168        Break;
    11701169      end;
     
    11741173        ParseState := psFinished;
    11751174        Inc(I);
     1175        Result := True;
    11761176        Break;
    11771177      end else
     
    11821182        while True do begin
    11831183          Inc(I);
     1184          if I >= Lines.Count then Break;
    11841185          Line2 := Lines[I];
    1185           if (Length(Lines[I]) > 0) and (Line2[1] = ' ') then begin
    1186             Value := Value + Trim(Lines[I]);
     1186          if (Length(Line2) > 0) and (Line2[1] = ' ') then begin
     1187            Value := Value + Trim(Line2);
    11871188          end else
    1188           if (Length(Lines[I]) > 0) and (Length(Value) > 0) and (Value[Length(Value)] = '=') and
    1189             (Lines[I][1] = '=') then begin
    1190             Value := Value + Copy(Trim(Lines[I]), 2, MaxInt);
     1189          if (Length(Line2) > 0) and (Length(Value) > 0) and (Value[Length(Value)] = '=') and
     1190            (Line2[1] = '=') then begin
     1191            Value := Value + Copy(Trim(Line2), 2, MaxInt);
    11911192          end else begin
    11921193            Dec(I);
     
    12081209      end else begin
    12091210        ContactsFile.Error(SExpectedProperty, I + 1);
    1210         I := -1;
    12111211        Break;
    12121212      end;
     
    12141214    Inc(I);
    12151215  end;
    1216   Result := I;
     1216  if Result then StartLine := I;
    12171217end;
    12181218
     
    12331233var
    12341234  Lines: TStringList;
     1235  StartLine: Integer;
    12351236begin
    12361237  Lines := TStringList.Create;
     
    12451246    end;
    12461247    {$ENDIF}
    1247     LoadFromStrings(Lines);
     1248    StartLine := 0;
     1249    LoadFromStrings(Lines, StartLine);
    12481250  finally
    12491251    Lines.Free;
     
    12851287  Contact: TContact;
    12861288  I: Integer;
    1287   NewI: Integer;
    12881289begin
    12891290  Contacts.Clear;
     
    12931294    Contact := TContact.Create;
    12941295    Contact.ContactsFile := Self;
    1295     NewI := Contact.LoadFromStrings(Lines, I);
    1296     if NewI <= Lines.Count then begin
    1297       if NewI <> -1 then begin
    1298         Contacts.Add(Contact);
    1299         I := NewI;
    1300       end else begin
    1301         FreeAndNil(Contact);
    1302         Inc(I);
    1303       end;
     1296    if Contact.LoadFromStrings(Lines, I) then begin
     1297      Contacts.Add(Contact);
    13041298    end else begin
    13051299      FreeAndNil(Contact);
    1306       Break;
     1300      Inc(I);
    13071301    end;
    13081302  end;
Note: See TracChangeset for help on using the changeset viewer.