User:PerfektesChaos/WikidiffLX/coding
Implementation suggestions for WikidiffLX in C++ code.
Survey
[edit]Migration from Wikidiff2
[edit]The development was based on wikidiff2 (rev 84056).
- wikidiff2.cpp
- WikidiffLX.cpp – Re-written and extended.
- wikidiff2.h
- Split into WikidiffLX.h class and WDLX_config.h configuration.
- Word.h
- Moved into Word.cpp – extension changed, small amendments
- Word.h – class declaration only
- DiffEngine.h
- Name of include wikidiff2.h adapted.
- (actually also DiffEngine.cpp implementation)
New files:
- Line.cpp and Line.h
- WDLX_config.h general configuration separated for integration, testing and debugging purposes.
Minor changes against Wikidiff2
[edit]Envision presentation without line number headers
[edit]Make any use of line number headers dependent on new macro NO_LINE_NUMBERS if one day decided to skip these numbers.
#ifndef NO_LINE_NUMBERS
Reserve buffer for line number headers once
[edit]Reserve space for line number headers once only.
class WikidiffLX {
#ifndef NO_LINE_NUMBERS
private:
char scratch256[256];
#endif
Avoid trouble with possible long characters
[edit]wchar_t was replaced by explicitly unsigned long in order to prevent C90 fuzz from compilers. 32bit long characters are required for CJK. There is no need to adapt on 16bit characters silently.
For the same reason the type of nextUtf8Char() is unsigned int now.
Number of context lines
[edit]The number of context lines became class member now rather than passing through many argument lists. Actually it is a kind of fixed global parameter but may be subject to change without new compilation.
General notes
[edit]op codes
[edit]The result of the diff engine is an amalgamated sequence of parts, containing the original from and to as well as a code op as follows. For lines this is displayed by yellow and green colour:
- copy (0)
Entire part absolutely unchanged.
No change. | No change. |
- change (3)
Content of parts between two neighbouring copy chunks changed, number of parts may differ.
Something modified. | Something changed. |
- del (1)
Count of parts between neighbouring copy chunks differs and another content; from has the greater number and this is attached to from while to is null.
Deleted paragraph. |
- add (2)
Count of parts between neighbouring copy chunks differs and another content; to has the greater number and this is attached to to while from is null.
Added paragraph. |
Note that from and to lines with the same op code are merged into arrays of pointers to line by diff engine.