dolibarr 20.0.0
Diff Class Reference

A class containing functions for computing diffs and formatting the output. More...

Collaboration diagram for Diff:

Static Public Member Functions

static compare ($string1, $string2, $compareCharacters=false)
 Returns the diff for two strings.
 
static compareFiles ( $file1, $file2, $compareCharacters=false)
 Returns the diff for two files.
 
static toString ($diff, $separator="\n")
 Returns a diff as a string, where unmodified lines are prefixed by ' ', deletions are prefixed by '- ', and insertions are prefixed by '+ '.
 
static toHTML ($diff, $separator='< br >')
 Returns a diff as an HTML string, where unmodified lines are contained within 'span' elements, deletions are contained within 'del' elements, and insertions are contained within 'ins' elements.
 
static toTable ($diff, $indentation='', $separator='< br >')
 Returns a diff as an HTML table.
 

Static Private Member Functions

static computeTable ($sequence1, $sequence2, $start, $end1, $end2)
 Returns the table of longest common subsequence lengths for the specified sequences.
 
static generatePartialDiff ($table, $sequence1, $sequence2, $start)
 Returns the partial diff for the specified sequences, in reverse order.
 
static getCellContent ($diff, $indentation, $separator, &$index, $type)
 Returns the content of the cell, for use in the toTable function.
 

Detailed Description

A class containing functions for computing diffs and formatting the output.

We can compare 2 strings or 2 files (as one string or line by line)

Definition at line 18 of file utils_diff.class.php.

Member Function Documentation

◆ compare()

static Diff::compare ( $string1,
$string2,
$compareCharacters = false )
static

Returns the diff for two strings.

The return value is an array, each of whose values is an array containing two values: a line (or character, if $compareCharacters is true), and one of the constants DIFF\UNMODIFIED (the line or character is in both strings), DIFF\DELETED (the line or character is only in the first string), and DIFF\INSERTED (the line or character is only in the second string). The parameters are:

Parameters
string$string1First string
string$string2Second string
boolean$compareCharacterstrue to compare characters, and false to compare lines; this optional parameter defaults to false
Returns
array<array{0:string,1:int<0,2>}> Array of diff

Definition at line 38 of file utils_diff.class.php.

References computeTable(), and generatePartialDiff().

Referenced by compareFiles().

◆ compareFiles()

static Diff::compareFiles ( $file1,
$file2,
$compareCharacters = false )
static

Returns the diff for two files.

The parameters are:

Parameters
string$file1Path to the first file
string$file2Path to the second file
boolean$compareCharacterstrue to compare characters, and false to compare lines; this optional parameter defaults to false
Returns
array<array{0:string,1:int<0,2>}> Array of diff

Definition at line 99 of file utils_diff.class.php.

References compare().

◆ computeTable()

static Diff::computeTable ( $sequence1,
$sequence2,
$start,
$end1,
$end2 )
staticprivate

Returns the table of longest common subsequence lengths for the specified sequences.

The parameters are:

Parameters
string$sequence1the first sequence
string$sequence2the second sequence
int$startthe starting index
int$end1the ending index for the first sequence
int$end2the ending index for the second sequence
Returns
array<array<int>> array of diff

Definition at line 123 of file utils_diff.class.php.

Referenced by compare().

◆ generatePartialDiff()

static Diff::generatePartialDiff ( $table,
$sequence1,
$sequence2,
$start )
staticprivate

Returns the partial diff for the specified sequences, in reverse order.

The parameters are:

Parameters
array<array{0:string,1:int<0,2>}>$table the table returned by the computeTable function
string$sequence1the first sequence
string$sequence2the second sequence
int$startthe starting index
Returns
array<array{0:string,1:int<0,2>}> array of diff

Definition at line 163 of file utils_diff.class.php.

Referenced by compare().

◆ getCellContent()

static Diff::getCellContent ( $diff,
$indentation,
$separator,
& $index,
$type )
staticprivate

Returns the content of the cell, for use in the toTable function.

The parameters are:

Parameters
array<array{0:string,1:int<0,2>}>$diff the diff array
string$indentationindentation to add to every line of the generated HTML
string$separatorthe separator between lines
string$indexthe current index, passes by reference
string$typethe type of line
Returns
string HTML string

Definition at line 378 of file utils_diff.class.php.

Referenced by toTable().

◆ toHTML()

static Diff::toHTML ( $diff,
$separator = '<br>' )
static

Returns a diff as an HTML string, where unmodified lines are contained within 'span' elements, deletions are contained within 'del' elements, and insertions are contained within 'ins' elements.

The parameters are:

Parameters
array<array{0:string,1:int<0,2>}>$diff the diff array
string$separatorthe separator between lines; this optional parameter defaults to '
'
Returns
string HTML string

Definition at line 245 of file utils_diff.class.php.

References dol_escape_htmltag().

◆ toString()

static Diff::toString ( $diff,
$separator = "\n" )
static

Returns a diff as a string, where unmodified lines are prefixed by ' ', deletions are prefixed by '- ', and insertions are prefixed by '+ '.

The parameters are:

Parameters
array<array{0:string,1:int<0,2>}>$diff the diff array
string$separatorthe separator between lines; this optional parameter defaults to "\n"
Returns
string String

Definition at line 208 of file utils_diff.class.php.

◆ toTable()

static Diff::toTable ( $diff,
$indentation = '',
$separator = '<br>' )
static

Returns a diff as an HTML table.

The parameters are:

Parameters
array<array{0:string,1:int<0,2>}>$diff the diff array
string$indentationindentation to add to every line of the generated HTML; this optional parameter defaults to ''
string$separatorthe separator between lines; this optional parameter defaults to '
'
Returns
string HTML string

Definition at line 283 of file utils_diff.class.php.

References getCellContent().


The documentation for this class was generated from the following file: