Forum > SynEdit

Compare two text lines and highlight difference

<< < (7/7)

DomingoGP:

--- Quote ---The result: last character missing from the compare.
--- End quote ---

@totya

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


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    //finally, append any trailing matches onto compareList ...    with FLastCompareRec do    begin      AddChangeChr(oldIndex1,len1{len1Minus1}-oldIndex1, ckNone);   //<DomingoGP SOLVES BUG: strings index are 1 based not 0 based.    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:

--- Quote from: DomingoGP on February 09, 2023, 09:59:42 pm ---
--- Quote ---The result: last character missing from the compare.
--- End quote ---
I have found the problem with the last char in TDiff in the
--- End quote ---

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:
You are welcome1.


--- Quote ---But I will look your Diff2.pas version too.
--- End quote ---

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

totya:

--- Quote from: DomingoGP on February 10, 2023, 06:40:28 pm ---You are welcome1.


--- Quote ---But I will look your Diff2.pas version too.
--- End quote ---

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

--- End quote ---

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:


--- Quote from: Thaddy on February 09, 2023, 01:11:25 pm ---Because you use the wrong mode: you should have used {$mode delphiunicode}
--- End quote ---

Phoenix:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---..{$IFDEF FPC}function Execute(const alist1, alist2: TIntegerList; const aDiffAlgorithm: TDiffAlgorithm): boolean; overload;{$ELSE}.. 

Navigation

[0] Message Index

[*] Previous page

Go to full version