Changeset 135 for trunk


Ignore:
Timestamp:
Jun 23, 2022, 10:22:43 PM (3 years ago)
Author:
chronos
Message:
  • Modified: Normalize line endings according vCard format specification.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/Common.lpk

    r134 r135  
    4141Source: https://svn.zdechov.net/PascalClassLibrary/Common/"/>
    4242    <License Value="Copy left."/>
    43     <Version Minor="9"/>
     43    <Version Minor="10"/>
    4444    <Files Count="30">
    4545      <Item1>
  • trunk/Packages/Common/StopWatch.pas

    r127 r135  
    55
    66uses
    7   {$IFDEF Windows}Windows,{$ENDIF}
     7  {$IFDEF WINDOWS}Windows,{$ENDIF}
    88  SysUtils, DateUtils;
    99
     
    4141  fIsRunning := False;
    4242
    43   {$IFDEF Windows}
     43  {$IFDEF WINDOWS}
    4444  fIsHighResolution := QueryPerformanceFrequency(fFrequency) ;
    4545  {$ELSE}
  • trunk/Packages/VCard/UVCard.pas

    r133 r135  
    253253  VCardEncoding = 'ENCODING';
    254254  VCardCharset = 'CHARSET';
     255  VCardLineEnding = #13#10;
    255256
    256257procedure Register;
     
    17651766begin
    17661767  with Output do begin
     1768    LineBreak := VCardLineEnding;
    17671769    Add(VCardBegin);
    17681770    for I := 0 to Properties.Count - 1 do
  • trunk/UCore.pas

    r134 r135  
    625625  {$IFOPT D+}
    626626  ATest.Enabled := True;
     627  AFileCompare.Enabled := True;
    627628  {$ENDIF}
    628629  {$IFOPT D-}
    629630  ATest.Enabled := False;
     631  AFileCompare.Enabled := False;
    630632  {$ENDIF}
    631633  ATest.Visible := ATest.Enabled;
     634  AFileCompare.Visible := AFileCompare.Enabled;
    632635end;
    633636
  • trunk/UTestCases.pas

    r129 r135  
    1616const
    1717  VCardVersion = 'VERSION:2.1';
     18  UnixLineEnding = #10;
     19  MacLineEnding = #13;
    1820
    1921function BeginEnd(Text: string; WithVersion: Boolean = True): string;
    2022begin
    21   Result := VCardBegin + LineEnding;
    22   if WithVersion then Result := Result + VCardVersion + LineEnding;
    23   Result := Result + Text + VCardEnd + LineEnding;
     23  Result := VCardBegin + VCardLineEnding;
     24  if WithVersion then Result := Result + VCardVersion + VCardLineEnding;
     25  Result := Result + Text + VCardEnd + VCardLineEnding;
    2426end;
    2527
     
    3032    with TTestCaseLoadSave(AddNew('Load and save', TTestCaseLoadSave)) do begin
    3133      Input := BeginEnd(
    32         'N:Surname;Name' + LineEnding +
    33         'FN:Name Surname' + LineEnding);
     34        'N:Surname;Name' + VCardLineEnding +
     35        'FN:Name Surname' + VCardLineEnding);
    3436      Output := Input;
    3537    end;
    3638    with TTestCaseLoadSave(AddNew('Long text', TTestCaseLoadSave)) do begin
    3739      Input := BeginEnd(
    38         'NOTE:This is some long test which is really multi-lined each line is on dif' + LineEnding +
    39         ' ferent line so it is on multiple lines.' + LineEnding);
     40        'NOTE:This is some long test which is really multi-lined each line is on dif' + VCardLineEnding +
     41        ' ferent line so it is on multiple lines.' + VCardLineEnding);
    4042      Output := Input;
    4143    end;
    4244    with TTestCaseLoadSave(AddNew('Multi-line', TTestCaseLoadSave)) do begin
    4345      Input := BeginEnd(
    44         'NOTE:First line\nsecond line\nempty line\n\nlast line' + LineEnding);
     46        'NOTE:First line\nsecond line\nempty line\n\nlast line' + VCardLineEnding);
    4547     Output := Input;
    4648    end;
    4749    with TTestCaseLoadSave(AddNew('Quoted-printable load-save', TTestCaseLoadSave)) do begin
    4850      Input := BeginEnd(
    49         'FN;ENCODING=QUOTED-PRINTABLE:Jm=C3=A9no=20P=C5=99=C3=ADjmen=C3=AD' + LineEnding);
     51        'FN;ENCODING=QUOTED-PRINTABLE:Jm=C3=A9no=20P=C5=99=C3=ADjmen=C3=AD' + VCardLineEnding);
    5052      Output := Input;
    5153    end;
    5254    with TTestCaseLoadSave(AddNew('Quoted-printable load-save multi-line', TTestCaseLoadSave)) do begin
    5355      Input := BeginEnd(
    54         'FN;ENCODING=QUOTED-PRINTABLE:Jm=C3=A9no=20P=C5=99=C3=ADjmen=C3=ADJm=C3=A9n=' + LineEnding +
    55         'o=20P=C5=99=C3=ADjmen=C3=AD' + LineEnding);
     56        'FN;ENCODING=QUOTED-PRINTABLE:Jm=C3=A9no=20P=C5=99=C3=ADjmen=C3=ADJm=C3=A9n=' + VCardLineEnding +
     57        'o=20P=C5=99=C3=ADjmen=C3=AD' + VCardLineEnding);
    5658      Output := Input;
    5759    end;
    5860    with TTestCaseLoadSave(AddNew('Base64 load-save (encoding=base64)', TTestCaseLoadSave)) do begin
    5961      Input := BeginEnd(
    60         'FN;ENCODING=BASE64:VGVzdCBzdHJpbmc=' + LineEnding);
     62        'FN;ENCODING=BASE64:VGVzdCBzdHJpbmc=' + VCardLineEnding);
    6163      Output := Input;
    6264    end;
    6365    with TTestCaseLoadSave(AddNew('Base64 load-save (base64)', TTestCaseLoadSave)) do begin
    6466      Input := BeginEnd(
    65         'FN;BASE64:VGVzdCBzdHJpbmc=' + LineEnding);
     67        'FN;BASE64:VGVzdCBzdHJpbmc=' + VCardLineEnding);
    6668      Output := Input;
    6769    end;
    6870    with TTestCaseLoadSave(AddNew('Base64 load-save (encoding=b)', TTestCaseLoadSave)) do begin
    6971      Input := BeginEnd(
    70         'FN;ENCODING=B:VGVzdCBzdHJpbmc=' + LineEnding);
     72        'FN;ENCODING=B:VGVzdCBzdHJpbmc=' + VCardLineEnding);
    7173      Output := Input;
    7274    end;
    7375    with TTestCaseLoadSave(AddNew('Base64 load-save multi-line', TTestCaseLoadSave)) do begin
    7476      Input := BeginEnd(
    75         'FN;ENCODING=BASE64:U29tZSB2ZXJ5IGxvbmcgc3RyaW5nIFNvbWUgdmVyeSBsb25nIHN0cmlu' + LineEnding +
    76         ' ZyBTb21lIHZlcnkgbG9uZyBzdHJpbmcgU29tZSB2ZXJ5IGxvbmcgc3RyaW5n' + LineEnding);
     77        'FN;ENCODING=BASE64:U29tZSB2ZXJ5IGxvbmcgc3RyaW5nIFNvbWUgdmVyeSBsb25nIHN0cmlu' + VCardLineEnding +
     78        ' ZyBTb21lIHZlcnkgbG9uZyBzdHJpbmcgU29tZSB2ZXJ5IGxvbmcgc3RyaW5n' + VCardLineEnding);
    7779      Output := Input;
    7880    end;
     
    8789    end;
    8890    with TTestCaseLoadSave(AddNew('Missing end', TTestCaseLoadSave)) do begin
    89       Input := VCardBegin + LineEnding +
    90         VCardVersion + LineEnding +
    91         'N:Surname;Name' + LineEnding +
    92         'FN:Name Surname' + LineEnding;
     91      Input := VCardBegin + VCardLineEnding +
     92        VCardVersion + VCardLineEnding +
     93        'N:Surname;Name' + VCardLineEnding +
     94        'FN:Name Surname' + VCardLineEnding;
    9395      Output := '';
    9496    end;
    9597    with TTestCaseLoadSave(AddNew('Missing start', TTestCaseLoadSave)) do begin
    96       Input := VCardVersion + LineEnding +
    97         'N:Surname;Name' + LineEnding +
    98         'FN:Name Surname' + LineEnding +
    99         VCardEnd + LineEnding;
     98      Input := VCardVersion + VCardLineEnding +
     99        'N:Surname;Name' + VCardLineEnding +
     100        'FN:Name Surname' + VCardLineEnding +
     101        VCardEnd + VCardLineEnding;
    100102      Output := '';
    101103    end;
     
    103105      Index := cfFullName;
    104106      Value := 'Name Surname';
    105       Input := BeginEnd('FN:' + Value + LineEnding);
     107      Input := BeginEnd('FN:' + Value + VCardLineEnding);
    106108    end;
    107109    with TTestCaseCheckProperty(AddNew('Escaped new lines in text', TTestCaseCheckProperty)) do begin
    108110      Index := cfNote;
    109111      Value := 'Line' + #13#10 + 'Line';
    110       Input := BeginEnd('NOTE:Line\nLine' + LineEnding);
     112      Input := BeginEnd('NOTE:Line\nLine' + VCardLineEnding);
    111113    end;
    112114    with TTestCaseCheckProperty(AddNew('Compound value', TTestCaseCheckProperty)) do begin
    113115      Index := cfFirstName;
    114116      Value := 'FirstName';
    115       Input := BeginEnd('N:Surname;FirstName;;;' + LineEnding);
     117      Input := BeginEnd('N:Surname;FirstName;;;' + VCardLineEnding);
    116118    end;
    117119    with TTestCaseCheckProperty(AddNew('Quoted-printable special symbols', TTestCaseCheckProperty)) do begin
     
    119121      Value := 'Jméno Příjmení';
    120122      Input := BeginEnd(
    121         'FN;ENCODING=QUOTED-PRINTABLE:Jm=C3=A9no=20P=C5=99=C3=ADjmen=C3=AD' + LineEnding);
     123        'FN;ENCODING=QUOTED-PRINTABLE:Jm=C3=A9no=20P=C5=99=C3=ADjmen=C3=AD' + VCardLineEnding);
    122124    end;
    123125    with TTestCaseCheckProperty(AddNew('Base64 special symbols', TTestCaseCheckProperty)) do begin
    124126      Index := cfFullName;
    125127      Value := 'Jméno Příjmení';
    126       Input := BeginEnd('FN;ENCODING=BASE64:Sm3DqW5vIFDFmcOtam1lbsOt' + LineEnding);
     128      Input := BeginEnd('FN;ENCODING=BASE64:Sm3DqW5vIFDFmcOtam1lbsOt' + VCardLineEnding);
    127129    end;
    128130    with TTestCaseLoadSave(AddNew('Remove exact duplicates', TTestCaseLoadSave)) do begin
    129131      Input := BeginEnd(
    130         'N:Surname;Name' + LineEnding +
    131         'FN:Name Surname' + LineEnding) +
     132        'N:Surname;Name' + VCardLineEnding +
     133        'FN:Name Surname' + VCardLineEnding) +
    132134        BeginEnd(
    133         'N:Surname2;Name2' + LineEnding +
    134         'FN:Name2 Surname2' + LineEnding) +
     135        'N:Surname2;Name2' + VCardLineEnding +
     136        'FN:Name2 Surname2' + VCardLineEnding) +
    135137        BeginEnd(
    136         'N:Surname;Name' + LineEnding +
    137         'FN:Name Surname' + LineEnding) +
     138        'N:Surname;Name' + VCardLineEnding +
     139        'FN:Name Surname' + VCardLineEnding) +
    138140        BeginEnd(
    139         'N:Surname;Name' + LineEnding +
    140         'FN:Name Surname' + LineEnding +
    141         'NOTE:Note' + LineEnding) +
     141        'N:Surname;Name' + VCardLineEnding +
     142        'FN:Name Surname' + VCardLineEnding +
     143        'NOTE:Note' + VCardLineEnding) +
    142144        BeginEnd(
    143         'N:Surname;Name' + LineEnding +
    144         'FN:Name Surname' + LineEnding);
     145        'N:Surname;Name' + VCardLineEnding +
     146        'FN:Name Surname' + VCardLineEnding);
    145147      Action := akRemoveExactDuplicates;
    146148      Output := BeginEnd(
    147         'N:Surname;Name' + LineEnding +
    148         'FN:Name Surname' + LineEnding) +
     149        'N:Surname;Name' + VCardLineEnding +
     150        'FN:Name Surname' + VCardLineEnding) +
    149151        BeginEnd(
    150         'N:Surname2;Name2' + LineEnding +
    151         'FN:Name2 Surname2' + LineEnding) +
     152        'N:Surname2;Name2' + VCardLineEnding +
     153        'FN:Name2 Surname2' + VCardLineEnding) +
    152154        BeginEnd(
    153         'N:Surname;Name' + LineEnding +
    154         'FN:Name Surname' + LineEnding +
    155         'NOTE:Note' + LineEnding);
     155        'N:Surname;Name' + VCardLineEnding +
     156        'FN:Name Surname' + VCardLineEnding +
     157        'NOTE:Note' + VCardLineEnding);
     158    end;
     159    with TTestCaseLoadSave(AddNew('Normalize Unix line endings', TTestCaseLoadSave)) do begin
     160      Input := VCardBegin + UnixLineEnding +
     161        VCardVersion + UnixLineEnding +
     162        'N:Surname;Name' + UnixLineEnding +
     163        'FN:Name Surname' + UnixLineEnding +
     164        VCardEnd + UnixLineEnding;
     165      Output := VCardBegin + VCardLineEnding +
     166        VCardVersion + VCardLineEnding +
     167        'N:Surname;Name' + VCardLineEnding +
     168        'FN:Name Surname' + VCardLineEnding +
     169        VCardEnd + VCardLineEnding;
     170    end;
     171    with TTestCaseLoadSave(AddNew('Normalize Mac line endings', TTestCaseLoadSave)) do begin
     172      Input := VCardBegin + MacLineEnding +
     173        VCardVersion + MacLineEnding +
     174        'N:Surname;Name' + MacLineEnding +
     175        'FN:Name Surname' + MacLineEnding +
     176        VCardEnd + MacLineEnding;
     177      Output := VCardBegin + VCardLineEnding +
     178        VCardVersion + VCardLineEnding +
     179        'N:Surname;Name' + VCardLineEnding +
     180        'FN:Name Surname' + VCardLineEnding +
     181        VCardEnd + VCardLineEnding;
    156182    end;
    157183  end;
Note: See TracChangeset for help on using the changeset viewer.