PHP Class Eloquent\Phony\Difference\DifferenceSequenceMatcher

Copyright (c) 2009 Chris Boulton All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - Neither the name of the Chris Boulton nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Show file Open project: eloquent/phony Class Usage Examples

Public Methods

Method Description
__construct ( array $a, array $b ) Construct a new sequence matcher.
getOpCodes ( ) : array Return a list of all of the opcodes for the differences between the two strings.

Private Methods

Method Description
chainB ( ) Generate the internal arrays containing the list of junk and non-junk characters for the second ($b) sequence.
findLongestMatch ( integer $alo, integer $ahi, integer $blo, integer $bhi ) : array Find the longest matching block in the two sequences, as defined by the lower and upper constraints for each sequence. (for the first sequence, $alo - $ahi and for the second sequence, $blo - $bhi).
getMatchingBlocks ( ) : array Return a nested set of arrays for all of the matching sub-sequences in the strings $a and $b.
tupleSort ( array $a, array $b ) : integer Sort an array by the nested arrays it contains. Helper function for getMatchingBlocks.

Method Details

__construct() public method

Construct a new sequence matcher.
public __construct ( array $a, array $b )
$a array An array containing the sequence to compare against.
$b array An array containing the sequence to compare.

getOpCodes() public method

The nested array returned contains an array describing the opcode which includes: 0 - The type of tag (as described below) for the opcode. 1 - The beginning line in the first sequence. 2 - The end line in the first sequence. 3 - The beginning line in the second sequence. 4 - The end line in the second sequence. The different types of tags include: replace - The string from $i1 to $i2 in $a should be replaced by the string in $b from $j1 to $j2. delete - The string in $a from $i1 to $j2 should be deleted. insert - The string in $b from $j1 to $j2 should be inserted at $i1 in $a. equal - The two strings with the specified ranges are equal.
public getOpCodes ( ) : array
return array Array of the opcodes describing the differences between the strings.