Changeset 59 for trunk/UContact.pas
- Timestamp:
- Dec 8, 2021, 11:33:52 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UContact.pas
r58 r59 169 169 resourcestring 170 170 SVCardFile = 'vCard file'; 171 SFoundPropertiesBeforeBlockStart = 'Found properties before the start of block';172 SFoundBlockEndWithoutBlockStart = 'Found block end without block start';173 171 SExpectedVCardBegin = 'Expected vCard begin'; 174 172 SFieldIndexNotDefined = 'Field index not defined'; … … 279 277 end; 280 278 279 function EndsWith(Text, What: string): Boolean; 280 begin 281 Result := Copy(Text, Length(Text) - Length(What) + 1, MaxInt) = What; 282 if Result then begin 283 Result := Result; 284 end; 285 end; 286 287 function EncodeEscaped(Text: string): string; 288 var 289 I: Integer; 290 begin 291 Result := ''; 292 I := 1; 293 while I <= Length(Text) do begin 294 if Text[I] in [',', '\', ';'] then Result := Result + '\' + Text[I] 295 else Result := Result + Text[I]; 296 Inc(I); 297 end; 298 end; 299 300 function DecodeEscaped(Text: string): string; 301 var 302 I: Integer; 303 Escaped: Boolean; 304 begin 305 Result := ''; 306 I := 1; 307 Escaped := False; 308 while I <= Length(Text) do begin 309 if Escaped then begin 310 Result := Result + Text[I]; 311 Escaped := False; 312 end else begin 313 if Text[I] = '\' then begin 314 Escaped := True; 315 end else Result := Result + Text[I]; 316 end; 317 Inc(I); 318 end; 319 end; 320 281 321 { TContactField } 282 322 … … 342 382 begin 343 383 I := 0; 344 while (I < Count) and (Items[I].Name <> Name) do Inc(I);384 while (I < Count) and (Items[I].Name <> Name) and (not EndsWith(Items[I].Name, '.' + Name)) do Inc(I); 345 385 if I < Count then Result := Items[I] 346 386 else Result := nil; … … 473 513 I: Integer; 474 514 begin 475 Result := Name = AName;515 Result := (Name = AName) or EndsWith(Name, '.' + AName); 476 516 if Result and (Length(Groups) > 0) then begin 477 517 for I := 0 to Length(Groups) - 1 do … … 639 679 Field := Parent.Fields.GetByIndex(Index); 640 680 if Field.ValueIndex <> -1 then begin 641 Result := Prop.ValueItem[Field.ValueIndex]681 Result := DecodeEscaped(Prop.ValueItem[Field.ValueIndex]) 642 682 end else Result := Prop.Value; 643 683 end else Result := ''; … … 664 704 if Assigned(Prop) then begin 665 705 if Field.ValueIndex <> -1 then begin 666 Prop.ValueItem[Field.ValueIndex] := AValue;706 Prop.ValueItem[Field.ValueIndex] := EncodeEscaped(AValue); 667 707 end else Prop.Value := AValue; 668 708 … … 747 787 OutText: string; 748 788 LinePrefix: string; 789 CutLength: Integer; 749 790 const 750 791 MaxLineLength = 73; … … 774 815 while True do begin 775 816 if Length(OutText) > MaxLineLength then begin 776 if (LineIndex > 0) and (LinePrefix = '') then LinePrefix := ' '; 777 Add(LinePrefix + Copy(OutText, 1, MaxLineLength)); 778 System.Delete(OutText, 1, MaxLineLength); 817 CutLength := MaxLineLength; 818 if Encoding = 'QUOTED-PRINTABLE' then begin 819 // Do not cut encoded items 820 if ((CutLength - 2) >= 1) and (OutText[CutLength - 2] = '=') then 821 Dec(CutLength, 2) 822 else if ((CutLength - 1) >= 1) and (OutText[CutLength - 1] = '=') then 823 Dec(CutLength, 1); 824 end; 825 Add(LinePrefix + Copy(OutText, 1, CutLength)); 826 LinePrefix := ' '; 827 System.Delete(OutText, 1, CutLength); 779 828 Inc(LineIndex); 780 829 Continue; … … 852 901 NewProperty.Attributes.Delete(0); 853 902 end; 854 NewProperty.Value := Value;903 NewProperty.Value := DecodeEscaped(Value); 855 904 NewProperty.EvaluateAttributes; 856 905 end else begin … … 881 930 var 882 931 Lines: TStringList; 883 I: Integer;884 932 begin 885 933 Lines := TStringList.Create; … … 892 940 end; 893 941 end; 894 I :=LoadFromStrings(Lines);942 LoadFromStrings(Lines); 895 943 finally 896 944 Lines.Free; … … 1053 1101 Contact: TContact; 1054 1102 I: Integer; 1103 NewI: Integer; 1055 1104 begin 1056 1105 inherited; … … 1069 1118 Contact := TContact.Create; 1070 1119 Contact.Parent := Self; 1071 I := Contact.LoadFromStrings(Lines, I); 1072 if (I <= Lines.Count) and (I <> -1) then Contacts.Add(Contact) 1073 else begin 1120 NewI := Contact.LoadFromStrings(Lines, I); 1121 if NewI <= Lines.Count then begin 1122 if NewI <> -1 then begin 1123 Contacts.Add(Contact); 1124 I := NewI; 1125 end else begin 1126 FreeAndNil(Contact); 1127 Inc(I); 1128 end; 1129 end else begin 1074 1130 FreeAndNil(Contact); 1075 1131 Break;
Note:
See TracChangeset
for help on using the changeset viewer.