dolibarr  17.0.4
Static Public Member Functions | Static Private Member Functions | List of all members
Diff Class Reference

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

Collaboration diagram for Diff:
Collaboration graph
[legend]

Static Public Member Functions

static compare ($string1, $string2, $compareCharacters=false)
 Returns the diff for two strings. More...
 
static compareFiles ( $file1, $file2, $compareCharacters=false)
 Returns the diff for two files. More...
 
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 '+ '. More...
 
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. More...
 
static toTable ($diff, $indentation='', $separator='< br >')
 Returns a diff as an HTML table. More...
 

Static Private Member Functions

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

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 17 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
string$compareCharacterstrue to compare characters, and false to compare lines; this optional parameter defaults to false
Returns
array Array of diff

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

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 of diff

Definition at line 98 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
string$startthe starting index
string$end1the ending index for the first sequence
string$end2the ending index for the second sequence
Returns
array array of diff

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

◆ generatePartialDiff()

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

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

The parameters are:

Parameters
string$tablethe table returned by the computeTable function
string$sequence1the first sequence
string$sequence2the second sequence
string$startthe starting index
Returns
array array of diff

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

◆ 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$diffthe 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 377 of file utils_diff.class.php.

◆ 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$diffthe diff array
string$separatorthe separator between lines; this optional parameter defaults to '
'
Returns
string HTML string

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

◆ 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$diffthe diff array
string$separatorthe separator between lines; this optional parameter defaults to "\n"
Returns
string String

Definition at line 207 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$diffthe 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 282 of file utils_diff.class.php.


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