- Timestamp:
- Feb 3, 2022, 10:08:07 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormTest.pas
r91 r92 48 48 49 49 uses 50 UCore, UFormTestCase ;50 UCore, UFormTestCase, UContact; 51 51 52 52 { TFormTest } … … 119 119 with TestCases do begin 120 120 with TTestCaseLoadSave(AddNew('Load and save', TTestCaseLoadSave)) do begin 121 Input := 'BEGIN:VCARD'+ LineEnding +121 Input := VCardBegin + LineEnding + 122 122 'VERSION:2.1' + LineEnding + 123 123 'N:Surname;Name' + LineEnding + 124 124 'FN:Name Surname' + LineEnding + 125 'END:VCARD' + LineEnding; 125 VCardEnd + LineEnding; 126 Output := Input; 127 end; 128 with TTestCaseLoadSave(AddNew('Long text', TTestCaseLoadSave)) do begin 129 Input := VCardBegin + LineEnding + 130 'VERSION:2.1' + LineEnding + 131 'NOTE:This is some long test which is really multi-lined each line is on d' + LineEnding + 132 ' ifferent line so it is on multiple lines.' + LineEnding + 133 VCardEnd + LineEnding; 126 134 Output := Input; 127 135 end; 128 136 with TTestCaseLoadSave(AddNew('Multi-line', TTestCaseLoadSave)) do begin 129 Input := 'BEGIN:VCARD'+ LineEnding +137 Input := VCardBegin + LineEnding + 130 138 'VERSION:2.1' + LineEnding + 131 'NOTE:This is some long test which is really multi-lined\neach line\nis on' + LineEnding + 132 ' different\nline so it is on multiple\nlines.' + LineEnding + 133 'END:VCARD' + LineEnding; 139 'NOTE:First line\nsecond line\nempty line\n\nlast line' + LineEnding + 140 VCardEnd + LineEnding; 134 141 Output := Input; 135 142 end; … … 142 149 end; 143 150 with TTestCaseLoadSave(AddNew('Begin only', TTestCaseLoadSave)) do begin 144 Input := 'BEGIN:VCARD';151 Input := VCardBegin; 145 152 Output := ''; 146 153 end; 147 154 with TTestCaseLoadSave(AddNew('Missing end', TTestCaseLoadSave)) do begin 148 Input := 'BEGIN:VCARD'+ LineEnding +155 Input := VCardBegin + LineEnding + 149 156 'VERSION:2.1' + LineEnding + 150 157 'N:Surname;Name' + LineEnding + 151 158 'FN:Name Surname' + LineEnding; 159 Output := ''; 160 end; 161 with TTestCaseLoadSave(AddNew('Missing start', TTestCaseLoadSave)) do begin 162 Input := 'VERSION:2.1' + LineEnding + 163 'N:Surname;Name' + LineEnding + 164 'FN:Name Surname' + LineEnding + 165 VCardEnd + LineEnding; 152 166 Output := ''; 153 167 end; -
trunk/UContact.pas
r91 r92 127 127 procedure SetModified(AValue: Boolean); 128 128 procedure DoOnModify; 129 procedure DetectMaxLineLength(Text: string); 129 130 public 130 131 Properties: TContactProperties; … … 170 171 TContactsFile = class(TDataFile) 171 172 private 173 FMaxLineLength: Integer; 172 174 FOnError: TErrorEvent; 173 175 procedure Error(Text: string; Line: Integer); … … 184 186 constructor Create; override; 185 187 destructor Destroy; override; 188 published 186 189 property OnError: TErrorEvent read FOnError write FOnError; 190 property MaxLineLength: Integer read FMaxLineLength write FMaxLineLength; 187 191 end; 188 192 189 193 const 190 194 VCardFileExt = '.vcf'; 195 VCardBegin = 'BEGIN:VCARD'; 196 VCardEnd = 'END:VCARD'; 191 197 192 198 … … 197 203 198 204 const 199 VCardBegin = 'BEGIN:VCARD'; 200 VCardEnd = 'END:VCARD'; 205 DefaultMaxLineLength = 75; 201 206 202 207 resourcestring … … 323 328 I: Integer; 324 329 O: Integer; 330 InNewLine: Boolean; 325 331 begin 326 332 Result := ''; … … 330 336 while I <= Length(Text) do begin 331 337 if Text[I] in [',', '\', ';'] then begin 338 InNewLine := False; 339 Result[O] := '\'; 340 SetLength(Result, Length(Result) + 1); 341 Inc(O); 342 Result[O] := Text[I]; 343 Inc(O); 344 end else 345 if Text[I] in [#13, #10] then begin 346 if not InNewLine then begin 332 347 Result[O] := '\'; 333 348 Inc(O); 334 Result[O] := Text[I];335 349 SetLength(Result, Length(Result) + 1); 350 Result[O] := 'n'; 336 351 Inc(O); 337 end else begin 338 Result[O] := Text[I]; 339 Inc(O); 352 InNewLine := True; 340 353 end; 354 end else begin 355 InNewLine := False; 356 Result[O] := Text[I]; 357 Inc(O); 358 end; 341 359 Inc(I); 342 360 end; … … 357 375 while I <= Length(Text) do begin 358 376 if Escaped then begin 359 Result[O] := Text[I]; 360 Inc(O); 377 if Text[I] = 'n' then begin 378 Result[O] := #13; 379 Inc(O); 380 Result[O] := #10; 381 Inc(O); 382 end else begin 383 Result[O] := Text[I]; 384 Inc(O); 385 end; 361 386 Escaped := False; 362 387 end else begin … … 940 965 Field: TContactField; 941 966 begin 942 if not Assigned(ContactsFile) then raise Exception.Create(SContactHasNoParent); 967 if not Assigned(ContactsFile) then 968 raise Exception.Create(SContactHasNoParent); 943 969 Field := GetFields.GetByIndex(Index); 944 970 if Assigned(Field) then begin … … 947 973 if Field.ValueIndex <> -1 then begin 948 974 Result := DecodeEscaped(Prop.ValueItem[Field.ValueIndex]) 949 end else Result := Prop.Value; 975 end else begin 976 if Field.DataType = dtString then Result := DecodeEscaped(Prop.Value) 977 else Result := Prop.Value; 978 end; 950 979 end else Result := ''; 951 980 end else raise Exception.Create(SFieldIndexNotDefined); … … 958 987 I: Integer; 959 988 begin 960 if not Assigned(ContactsFile) then raise Exception.Create(SContactHasNoParent); 989 if not Assigned(ContactsFile) then 990 raise Exception.Create(SContactHasNoParent); 961 991 Field := GetFields.GetByIndex(Index); 962 992 if Assigned(Field) then begin … … 972 1002 if Field.ValueIndex <> -1 then begin 973 1003 Prop.ValueItem[Field.ValueIndex] := EncodeEscaped(AValue); 974 end else Prop.Value := AValue; 1004 end else begin 1005 if Field.DataType = dtString then Prop.Value := EncodeEscaped(AValue) 1006 else Prop.Value := EncodeEscaped(AValue); 1007 end; 975 1008 976 1009 // Remove if empty … … 993 1026 begin 994 1027 if Assigned(FOnModify) then FOnModify(Self); 1028 end; 1029 1030 procedure TContact.DetectMaxLineLength(Text: string); 1031 var 1032 LineLength: Integer; 1033 begin 1034 LineLength := UTF8Length(Text); 1035 if LineLength > 1 then begin 1036 // Count one character less for folded line 1037 if Text[1] = ' ' then 1038 Dec(LineLength); 1039 end; 1040 if LineLength > ContactsFile.MaxLineLength then 1041 ContactsFile.MaxLineLength := LineLength; 995 1042 end; 996 1043 … … 1087 1134 LineIndex: Integer; 1088 1135 OutText: string; 1136 CutText: string; 1089 1137 LinePrefix: string; 1090 1138 CutLength: Integer; 1091 const1092 MaxLineLength = 73;1093 1139 begin 1094 1140 with Output do begin … … 1115 1161 LinePrefix := ''; 1116 1162 while True do begin 1117 if Length(OutText) >MaxLineLength then begin1118 CutLength := MaxLineLength;1163 if UTF8Length(OutText) > ContactsFile.MaxLineLength then begin 1164 CutLength := ContactsFile.MaxLineLength; 1119 1165 if Encoding = 'QUOTED-PRINTABLE' then begin 1120 1166 // Do not cut encoded items … … 1124 1170 Dec(CutLength, 1); 1125 1171 end; 1126 Add(LinePrefix + Copy(OutText, 1, CutLength)); 1172 CutText := UTF8Copy(OutText, 1, CutLength); 1173 Add(LinePrefix + CutText); 1127 1174 LinePrefix := ' '; 1128 System.Delete(OutText, 1, CutLength);1175 System.Delete(OutText, 1, Length(CutText)); 1129 1176 Inc(LineIndex); 1130 1177 Continue; … … 1157 1204 I := StartLine; 1158 1205 while I < Lines.Count do begin 1159 Line := Trim(Lines[I]); 1206 Line := Lines[I]; 1207 DetectMaxLineLength(Line); 1208 1160 1209 if Line = '' then begin 1161 1210 // Skip empty lines … … 1184 1233 if I >= Lines.Count then Break; 1185 1234 Line2 := Lines[I]; 1235 DetectMaxLineLength(Line2); 1186 1236 if (Length(Line2) > 0) and (Line2[1] = ' ') then begin 1187 Value := Value + Trim(Line2);1237 Value := Value + Copy(Line2, 2, MaxInt); 1188 1238 end else 1189 1239 if (Length(Line2) > 0) and (Length(Value) > 0) and (Value[Length(Value)] = '=') and 1190 1240 (Line2[1] = '=') then begin 1191 Value := Value + Copy( Trim(Line2), 2, MaxInt);1241 Value := Value + Copy(Line2, 2, MaxInt); 1192 1242 end else begin 1193 1243 Dec(I); … … 1289 1339 begin 1290 1340 Contacts.Clear; 1341 MaxLineLength := 10; 1291 1342 1292 1343 I := 0; … … 1353 1404 Contacts := TContacts.Create; 1354 1405 Contacts.ContactsFile := Self; 1406 MaxLineLength := DefaultMaxLineLength; 1355 1407 end; 1356 1408 -
trunk/vCardStudio.lpi
r91 r92 202 202 <IsPartOfProject Value="True"/> 203 203 <ComponentName Value="FormTest"/> 204 <HasResources Value="True"/> 204 205 <ResourceBaseClass Value="Form"/> 205 206 </Unit15> … … 212 213 <IsPartOfProject Value="True"/> 213 214 <ComponentName Value="FormTestCase"/> 215 <HasResources Value="True"/> 214 216 <ResourceBaseClass Value="Form"/> 215 217 </Unit17>
Note:
See TracChangeset
for help on using the changeset viewer.