49 [ $wordsBefore, $wordsBeforeStripped ] = $this->split( $linesBefore );
50 [ $wordsAfter, $wordsAfterStripped ] = $this->split( $linesAfter );
53 parent::__construct( $wordsBeforeStripped, $wordsAfterStripped );
56 $this->edits = [
new DiffOpChange( $linesBefore, $linesAfter ) ];
60 $editCount = count( $this->edits );
61 for ( $i = 0; $i < $editCount; $i++ ) {
62 $orig = &$this->edits[$i]->orig;
63 if ( is_array( $orig ) ) {
64 $orig = array_slice( $wordsBefore, $xi, count( $orig ) );
65 $xi += count( $orig );
68 $closing = &$this->edits[$i]->closing;
69 if ( is_array( $closing ) ) {
70 $closing = array_slice( $wordsAfter, $yi, count( $closing ) );
71 $yi += count( $closing );
81 private function split(
$lines ) {
85 foreach (
$lines as $line ) {
93 if ( preg_match_all(
'/ ( [^\S\n]+ | [0-9_A-Za-z\x80-\xff]+ | . ) (?: (?!< \n) [^\S\n])? /xs',
95 foreach ( $m[0] as $word ) {
98 foreach ( $m[1] as $stripped_word ) {
99 $stripped[] = $stripped_word;
104 return [ $words, $stripped ];
113 foreach ( $this->edits as $edit ) {
114 if ( $edit->type ==
'copy' ) {
116 } elseif ( $edit->orig ) {
117 $orig->addWords( $edit->orig,
'del' );
120 $lines = $orig->getLines();
131 foreach ( $this->edits as $edit ) {
132 if ( $edit->type ==
'copy' ) {
133 $closing->
addWords( $edit->closing );
134 } elseif ( $edit->closing ) {
135 $closing->addWords( $edit->closing,
'ins' );
138 $lines = $closing->getLines();
Class representing a 'diff' between two sequences of strings.
Performs a word-level diff on several lines.
__construct( $linesBefore, $linesAfter)
if(!file_exists( $CREDITS)) $lines