ILIAS  release_8 Revision v8.24
WordLevelDiff Class Reference
+ Inheritance diagram for WordLevelDiff:
+ Collaboration diagram for WordLevelDiff:

Public Member Functions

 __construct ($orig_lines, $closing_lines)
 Constructor. More...
 
 _split ($lines)
 
 orig ()
 Get the original set of lines. More...
 
 closing ()
 Get the closing set of lines. More...
 
- Public Member Functions inherited from MappedDiff
 __construct ( $from_lines, $to_lines, $mapped_from_lines, $mapped_to_lines)
 Constructor. More...
 
- Public Member Functions inherited from Diff
 __construct ($from_lines, $to_lines)
 Constructor. More...
 
 reverse ()
 Compute reversed Diff. More...
 
 isEmpty ()
 Check for empty diff. More...
 
 lcs ()
 Compute the length of the Longest Common Subsequence (LCS). More...
 
 orig ()
 Get the original set of lines. More...
 
 closing ()
 Get the closing set of lines. More...
 
 _check ($from_lines, $to_lines)
 Check a Diff for validity. More...
 

Data Fields

const MAX_LINE_LENGTH = 10000
 
- Data Fields inherited from Diff
 $edits
 

Detailed Description

Definition at line 1783 of file class.WordLevelDiff.php.

Constructor & Destructor Documentation

◆ __construct()

WordLevelDiff::__construct (   $from_lines,
  $to_lines 
)

Constructor.

Computes diff between sequences of strings.

Parameters
$from_linesarray An array of strings. (Typically these are lines from a file.)
$to_linesarray An array of strings.

Reimplemented from Diff.

Definition at line 1787 of file class.WordLevelDiff.php.

1788 {
1789 $fname = 'WordLevelDiff::WordLevelDiff';
1790 //wfProfileIn( $fname );
1791
1792 list($orig_words, $orig_stripped) = $this->_split($orig_lines);
1793 list($closing_words, $closing_stripped) = $this->_split($closing_lines);
1794
1796 $orig_words,
1797 $closing_words,
1798 $orig_stripped,
1799 $closing_stripped
1800 );
1801 //wfProfileOut( $fname );
1802 }
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct(), and _split().

+ Here is the call graph for this function:

Member Function Documentation

◆ _split()

WordLevelDiff::_split (   $lines)

Definition at line 1804 of file class.WordLevelDiff.php.

1805 {
1806 $fname = 'WordLevelDiff::_split';
1807 //wfProfileIn( $fname );
1808
1809 $words = array();
1810 $stripped = array();
1811 $first = true;
1812 foreach ($lines as $line) {
1813 # If the line is too long, just pretend the entire line is one big word
1814 # This prevents resource exhaustion problems
1815 if ($first) {
1816 $first = false;
1817 } else {
1818 $words[] = "\n";
1819 $stripped[] = "\n";
1820 }
1821 if (strlen($line) > self::MAX_LINE_LENGTH) {
1822 $words[] = $line;
1823 $stripped[] = $line;
1824 } else {
1825 $m = array();
1826 if (preg_match_all(
1827 '/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
1828 $line,
1829 $m
1830 )) {
1831 $words = array_merge($words, $m[0]);
1832 $stripped = array_merge($stripped, $m[1]);
1833 }
1834 }
1835 }
1836 //wfProfileOut( $fname );
1837 return array($words, $stripped);
1838 }

Referenced by __construct().

+ Here is the caller graph for this function:

◆ closing()

WordLevelDiff::closing ( )

Get the closing set of lines.

This reconstructs the $to_lines parameter passed to the constructor.

Returns
array The sequence of strings.

Reimplemented from Diff.

Definition at line 1858 of file class.WordLevelDiff.php.

1859 {
1860 $fname = 'WordLevelDiff::closing';
1861 //wfProfileIn( $fname );
1862 $closing = new _HWLDF_WordAccumulator();
1863
1864 foreach ($this->edits as $edit) {
1865 if ($edit->type == 'copy') {
1866 $closing->addWords($edit->closing);
1867 } elseif ($edit->closing) {
1868 $closing->addWords($edit->closing, 'ins');
1869 }
1870 }
1871 $lines = $closing->getLines();
1872 //wfProfileOut( $fname );
1873 return $lines;
1874 }

◆ orig()

WordLevelDiff::orig ( )

Get the original set of lines.

This reconstructs the $from_lines parameter passed to the constructor.

Returns
array The original sequence of strings.

Reimplemented from Diff.

Definition at line 1840 of file class.WordLevelDiff.php.

1841 {
1842 $fname = 'WordLevelDiff::orig';
1843 //wfProfileIn( $fname );
1844 $orig = new _HWLDF_WordAccumulator();
1845
1846 foreach ($this->edits as $edit) {
1847 if ($edit->type == 'copy') {
1848 $orig->addWords($edit->orig);
1849 } elseif ($edit->orig) {
1850 $orig->addWords($edit->orig, 'del');
1851 }
1852 }
1853 $lines = $orig->getLines();
1854 //wfProfileOut( $fname );
1855 return $lines;
1856 }

Field Documentation

◆ MAX_LINE_LENGTH

const WordLevelDiff::MAX_LINE_LENGTH = 10000

Definition at line 1785 of file class.WordLevelDiff.php.


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