Changeset 42 for trunk/UContact.pas
- Timestamp:
- Dec 2, 2021, 12:18:18 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UContact.pas
r40 r42 13 13 TErrorEvent = procedure (Text: string; Line: Integer) of object; 14 14 15 TDataType = (dtString, dtInteger, dtDate, dtDateTime, dtImage );15 TDataType = (dtString, dtInteger, dtDate, dtDateTime, dtImage, dtStringList); 16 16 17 17 TContactFieldIndex = (cfFirstName, cfMiddleName, cfLastName, cfTitleBefore, … … 53 53 54 54 TContactProperty = class 55 private 56 function GetValueItem(Index: Integer): string; 57 procedure SetValueItem(Index: Integer; AValue: string); 58 public 55 59 Name: string; 56 60 Attributes: TStringList; 57 Value s: TStringList;61 Value: string; 58 62 Encoding: string; 59 63 Charset: string; … … 65 69 constructor Create; 66 70 destructor Destroy; override; 71 property ValueItem[Index: Integer]: string read GetValueItem write SetValueItem; 67 72 end; 68 73 … … 264 269 { TContactProperty } 265 270 271 function TContactProperty.GetValueItem(Index: Integer): string; 272 var 273 List: TStringList; 274 begin 275 List := TStringList.Create; 276 try 277 List.Delimiter := ';'; 278 List.NameValueSeparator := '='; 279 List.StrictDelimiter := True; 280 List.DelimitedText := Value; 281 if Index < List.Count then 282 Result := List.Strings[Index] 283 else Result := ''; 284 finally 285 List.Free; 286 end; 287 end; 288 289 procedure TContactProperty.SetValueItem(Index: Integer; AValue: string); 290 var 291 List: TStringList; 292 begin 293 List := TStringList.Create; 294 try 295 List.Delimiter := ';'; 296 List.NameValueSeparator := '='; 297 List.StrictDelimiter := True; 298 List.DelimitedText := Value; 299 300 // Extend subitems count 301 while List.Count <= Index do 302 List.Add(''); 303 304 List.Strings[Index] := AValue; 305 306 // Remove empty items 307 while (List.Count > 0) and (List.Strings[List.Count - 1] = '') do 308 List.Delete(List.Count - 1); 309 310 Value := List.DelimitedText; 311 finally 312 List.Free; 313 end; 314 end; 315 266 316 procedure TContactProperty.EvaluateAttributes; 267 317 var … … 274 324 Encoding := Attributes.Values['ENCODING']; 275 325 if (Encoding = 'QUOTED-PRINTABLE') or (Encoding = 'BASE64') then begin 276 Value s.DelimitedText:= GetDecodedValue;326 Value := GetDecodedValue; 277 327 Attributes.Delete(Attributes.IndexOfName('ENCODING')); 278 328 end; … … 292 342 function TContactProperty.GetDecodedValue: string; 293 343 begin 294 if Encoding = 'BASE64' then 295 Result := DecodeStringBase64(Values.DelimitedText) 296 else 297 if Encoding = 'QUOTED-PRINTABLE' then 298 Result := DecodeQuotedPrintable(Values.DelimitedText) 344 if Encoding = 'BASE64' then begin 345 Result := DecodeStringBase64(Value) 346 end else 347 if Encoding = 'QUOTED-PRINTABLE' then begin 348 Result := DecodeQuotedPrintable(Value) 349 end 299 350 else Result := ''; 300 351 end; … … 330 381 Name := Source.Name; 331 382 Attributes.Assign(Source.Attributes); 332 Values.Assign(Source.Values); 383 Value := Source.Value; 384 Encoding := Source.Encoding; 385 Charset := Source.Charset; 333 386 end; 334 387 … … 339 392 Attributes.NameValueSeparator := '='; 340 393 Attributes.StrictDelimiter := True; 341 Values := TStringList.Create;342 Values.Delimiter := ';';343 Values.NameValueSeparator := '=';344 Values.StrictDelimiter := True;345 394 end; 346 395 347 396 destructor TContactProperty.Destroy; 348 397 begin 349 FreeAndNil(Values);350 398 FreeAndNil(Attributes); 351 399 inherited; … … 448 496 Field := Parent.Fields.GetByIndex(Index); 449 497 if Field.ValueIndex <> -1 then begin 450 if Field.ValueIndex < Prop.Values.Count then 451 Result := Prop.Values.Strings[Field.ValueIndex] 452 else Result := ''; 453 end else Result := Prop.Values.DelimitedText; 498 Result := Prop.ValueItem[Field.ValueIndex] 499 end else Result := Prop.Value; 454 500 end else Result := ''; 455 501 end; … … 473 519 if Assigned(Prop) then begin 474 520 if Field.ValueIndex <> -1 then begin 475 // Extend subitems count 476 while Prop.Values.Count <= Field.ValueIndex do 477 Prop.Values.Add(''); 478 479 Prop.Values.Strings[Field.ValueIndex] := AValue; 480 end else Prop.Values.DelimitedText := AValue; 481 482 // Remove empty items 483 while (Prop.Values.Count > 0) and (Prop.Values.Strings[Prop.Values.Count - 1] = '') do 484 Prop.Values.Delete(Prop.Values.Count - 1); 521 Prop.ValueItem[Field.ValueIndex] := AValue; 522 end else Prop.Value := AValue; 485 523 486 524 // Remove if empty 487 if Prop.Value s.Text= '' then begin525 if Prop.Value = '' then begin 488 526 Properties.Remove(Prop); 489 527 end; … … 595 633 AddNew('X-TIMES_CONTACTED', [], [], STimesContacted, cfXTimesContacted, dtString); 596 634 AddNew('X-LAST_TIME_CONTACTED', [], [], SLastTimeContacted, cfXLastTimeContacted, dtString); 597 AddNew('PHOTO', [], [], SPhoto, cfPhoto, dt String);635 AddNew('PHOTO', [], [], SPhoto, cfPhoto, dtImage); 598 636 AddNew('X-JABBER', [], [], SJabber, cfXJabber, dtString); 599 AddNew('BDAY', [], [], SDayOfBirth, cfDayOfBirth, dt String);600 AddNew('ANNIVERSARY', [], [], SAnniversary, cfAnniversary, dt String);637 AddNew('BDAY', [], [], SDayOfBirth, cfDayOfBirth, dtDate); 638 AddNew('ANNIVERSARY', [], [], SAnniversary, cfAnniversary, dtDate); 601 639 AddNew('REV', [], [], SRevision, cfRevision, dtString); 602 640 AddNew('UID', [], [], SUniqueIdentifier, cfUid, dtString); … … 641 679 I: Integer; 642 680 J: Integer; 643 Value: string;644 681 NameText: string; 645 682 begin … … 652 689 for J := 0 to Properties.Count - 1 do 653 690 with Properties[J] do begin 654 Value := Values.DelimitedText;655 691 if Pos(LineEnding, Value) > 0 then begin 656 692 NameText := Name; … … 719 755 if (Length(Lines[I]) > 0) and (Lines[I][1] = ' ') then begin 720 756 Value := Value + Trim(Lines[I]); 757 end else 758 if (Length(Lines[I]) > 0) and (Length(Value) > 0) and (Value[Length(Value)] = '=') and 759 (Lines[I][1] = '=') then begin 760 Value := Value + Copy(Trim(Lines[I]), 2, MaxInt); 721 761 end else begin 722 762 Dec(I); … … 734 774 NewProperty.Attributes.Delete(0); 735 775 end; 736 NewProperty.Value s.DelimitedText:= Value;776 NewProperty.Value := Value; 737 777 NewProperty.EvaluateAttributes; 738 778 end else Error(SFoundPropertiesBeforeBlockStart, I + 1);
Note:
See TracChangeset
for help on using the changeset viewer.