Recent

Author Topic: Compare two text lines and highlight difference  (Read 8093 times)

DomingoGP

  • Jr. Member
  • **
  • Posts: 80
Re: Compare two text lines and highlight difference
« Reply #30 on: February 09, 2023, 09:59:42 pm »
Quote
The result: last character missing from the compare.

@totya

I have found the problem with the last char in TDiff in the   
 function Execute(const s1, s2: string): boolean;

Code: Pascal  [Select][+][-]
  1.  
  2.    //finally, append any trailing matches onto compareList ...
  3.     with FLastCompareRec do
  4.     begin
  5.       AddChangeChr(oldIndex1,len1{len1Minus1}-oldIndex1, ckNone);   //<DomingoGP SOLVES BUG: strings index are 1 based not 0 based.
  6.     end;


Also I have modified the unit so the desired string type can be easily changed and I have set as unicodestring by default for FPC.

if you want you can try the demo provided, with modified TDiff2.pas. It works reasonably well for me. Anyway, as Martin said, unicode characters can consist on several widechars or codepoints, in which case it won't work as expected. As well as this it works with the most common characters like accented vowels áéíóú ñ ç.

Unicode is too complicated to cover all possible cases  :-[.

The https://github.com/DomingoGP/lazIdeDiffCompareFiles component don't compare strings, so it is not affected by this bug.

Sorry for my bad english.


totya

  • Hero Member
  • *****
  • Posts: 722
Re: Compare two text lines and highlight difference
« Reply #31 on: February 09, 2023, 10:45:11 pm »
Quote
The result: last character missing from the compare.
I have found the problem with the last char in TDiff in the

Seems to me your patch is working, thank you!

I use this https://github.com/rickard67/TextDiff version, and with your suggestion my last checked bug is disappear. :)

But I will look your Diff2.pas version too.

Thanks again!!!  O:-)

DomingoGP

  • Jr. Member
  • **
  • Posts: 80
Re: Compare two text lines and highlight difference
« Reply #32 on: February 10, 2023, 06:40:28 pm »
You are welcome1.

Quote
But I will look your Diff2.pas version too.

You don't need to do, basically is the same as  https://github.com/rickard67/TextDiff with minor changes.

totya

  • Hero Member
  • *****
  • Posts: 722
Re: Compare two text lines and highlight difference
« Reply #33 on: February 10, 2023, 06:45:57 pm »
You are welcome1.

Quote
But I will look your Diff2.pas version too.

You don't need to do, basically is the same as  https://github.com/rickard67/TextDiff with minor changes.

I saw that, indeed, and thank you agan.

The simplest way to use these Delphi codes, I think Thaddy idea is the best (simplest) without modified variable type etc needed:

Because you use the wrong mode: you should have used {$mode delphiunicode}

Phoenix

  • Full Member
  • ***
  • Posts: 109
Re: Compare two text lines and highlight difference
« Reply #34 on: September 02, 2023, 09:02:29 pm »
I noticed that the source has been improved
https://github.com/rickard67/TextDiff
it seems to work fine.

Note: the method header must be corrected to compile it
Diff.pas
Code: Pascal  [Select][+][-]
  1. ..
  2. {$IFDEF FPC}
  3. function Execute(const alist1, alist2: TIntegerList; const aDiffAlgorithm: TDiffAlgorithm): boolean; overload;
  4. {$ELSE}
  5. ..
  6.  

 

TinyPortal © 2005-2018