HumHub Documentation (unofficial)

Diff
in package

Diff

A comprehensive library for generating differences between two strings in multiple formats (unified, side by side HTML etc)

PHP version 5

Copyright (c) 2009 Chris Boulton chris.boulton@interspire.com

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.

Tags
author

Chris Boulton chris.boulton@interspire.com

copyright

(c) 2009 Chris Boulton

license

New BSD License http://www.opensource.org/licenses/bsd-license.php

version
1.1
link
http://github.com/chrisboulton/php-diff

Table of Contents

Properties

$a  : array<string|int, mixed>
$b  : array<string|int, mixed>
$defaultOptions  : array<string|int, mixed>
$groupedCodes  : array<string|int, mixed>
$options  : array<string|int, mixed>

Methods

__construct()  : mixed
The constructor.
getA()  : array<string|int, mixed>
Get a range of lines from $start to $end from the first comparison string and return them as an array. If no values are supplied, the entire string is returned. It's also possible to specify just one line to return only that line.
getB()  : array<string|int, mixed>
Get a range of lines from $start to $end from the second comparison string and return them as an array. If no values are supplied, the entire string is returned. It's also possible to specify just one line to return only that line.
getGroupedOpcodes()  : array<string|int, mixed>
Generate a list of the compiled and grouped opcodes for the differences between the two strings. Generally called by the renderer, this class instantiates the sequence matcher and performs the actual diff generation and return an array of the opcodes for it. Once generated, the results are cached in the diff class instance.
render()  : mixed
Render a diff using the supplied rendering class and return it.

Properties

$a

private array<string|int, mixed> $a = \null

The "old" sequence to use as the basis for the comparison.

$b

private array<string|int, mixed> $b = \null

The "new" sequence to generate the changes for.

$defaultOptions

private array<string|int, mixed> $defaultOptions = array('context' => 3, 'ignoreNewLines' => \false, 'ignoreWhitespace' => \false, 'ignoreCase' => \false)

Associative array of the default options available for the diff class and their default value.

$groupedCodes

private array<string|int, mixed> $groupedCodes = \null

Array containing the generated opcodes for the differences between the two items.

$options

private array<string|int, mixed> $options = array()

Array of the options that have been applied for generating the diff.

Methods

__construct()

The constructor.

public __construct(array<string|int, mixed> $a, array<string|int, mixed> $b[, array<string|int, mixed> $options = array() ]) : mixed
Parameters
$a : array<string|int, mixed>

Array containing the lines of the first string to compare.

$b : array<string|int, mixed>

Array containing the lines for the second string to compare.

$options : array<string|int, mixed> = array()

getA()

Get a range of lines from $start to $end from the first comparison string and return them as an array. If no values are supplied, the entire string is returned. It's also possible to specify just one line to return only that line.

public getA([int $start = 0 ][, int $end = null ]) : array<string|int, mixed>
Parameters
$start : int = 0

The starting number.

$end : int = null

The ending number. If not supplied, only the item in $start will be returned.

Return values
array<string|int, mixed>

Array of all of the lines between the specified range.

getB()

Get a range of lines from $start to $end from the second comparison string and return them as an array. If no values are supplied, the entire string is returned. It's also possible to specify just one line to return only that line.

public getB([int $start = 0 ][, int $end = null ]) : array<string|int, mixed>
Parameters
$start : int = 0

The starting number.

$end : int = null

The ending number. If not supplied, only the item in $start will be returned.

Return values
array<string|int, mixed>

Array of all of the lines between the specified range.

getGroupedOpcodes()

Generate a list of the compiled and grouped opcodes for the differences between the two strings. Generally called by the renderer, this class instantiates the sequence matcher and performs the actual diff generation and return an array of the opcodes for it. Once generated, the results are cached in the diff class instance.

public getGroupedOpcodes() : array<string|int, mixed>
Return values
array<string|int, mixed>

Array of the grouped opcodes for the generated diff.

render()

Render a diff using the supplied rendering class and return it.

public render(Diff_Renderer_Abstract $renderer) : mixed
Parameters
$renderer : Diff_Renderer_Abstract

An instance of the rendering object to use for generating the diff.

Return values
mixed

The generated diff. Exact return value depends on the rendered.


        
On this page

Search results