|
Perforce Chronicle 2012.2/486814
API Documentation
|
Wrapper for chunks of values in a diff result. More...
Public Member Functions | |
| __construct (array $values=null) | |
| Create a new chunk from a list of unchanged (flat) or changed (multi-dimensional deleted/inserted) values. | |
| getChunkType () | |
| Get the type of this chunk: same, insert, delete, change. | |
| getLeft ($index=null) | |
| Get the left-hand values for this diff chunk. | |
| getMaxValueCount () | |
| Get the highest number of values in left/right. | |
| getRawValues () | |
| Get the raw values array. | |
| getRight ($index=null) | |
| Get the right-hand values for this diff chunk. | |
| getSubDiff ($index, P4Cms_Diff_Options $options=null) | |
| Compare the left/right values at the specified index. | |
| isChange () | |
| Check if this diff chunk is of type change. | |
| isDelete () | |
| Check if this diff chunk is of type delete. | |
| isInsert () | |
| Check if this diff chunk is of type insert. | |
| isSame () | |
| Check if this diff chunk is of type same. | |
| isWhitespaceChange ($semantic=true) | |
| Check if this diff chunk a whitespace only change. | |
| setRawValues (array $values) | |
| Set the raw values array. | |
Public Attributes | |
| const | SIDE_LEFT = 'left' |
| const | SIDE_RIGHT = 'right' |
| const | TYPE_CHANGE = 'change' |
| const | TYPE_DELETE = 'delete' |
| const | TYPE_INSERT = 'insert' |
| const | TYPE_SAME = 'same' |
Protected Member Functions | |
| _getSide ($side, $index=null) | |
| Get the left or right-hand set of values for this diff chunk. | |
Protected Attributes | |
| $_values = null | |
Wrapper for chunks of values in a diff result.
Each chunk is either a consecutive block of unchanged values, or a block of deleted/inserted values.
| P4Cms_Diff_Chunk::__construct | ( | array $ | values = null | ) |
Create a new chunk from a list of unchanged (flat) or changed (multi-dimensional deleted/inserted) values.
| array | $values | optional - flat array for chunks of unchanged values multi-dimensional deleted/inserted array for chunks of changed values. |
{
$this->_values = is_array($values) ? $values : array();
}
| P4Cms_Diff_Chunk::_getSide | ( | $ | side, |
| $ | index = null |
||
| ) | [protected] |
Get the left or right-hand set of values for this diff chunk.
| string | $side | left or right-hand side. |
| null | int | $index | optional - the index of the value to get. |
{
$values = !$this->isSame()
? $this->_values[($side == static::SIDE_LEFT ? 'd' : 'i')]
: $this->_values;
if ($index !== null) {
return isset($values[$index]) ? $values[$index] : null;
}
return $values;
}
| P4Cms_Diff_Chunk::getChunkType | ( | ) |
Get the type of this chunk: same, insert, delete, change.
{
$values = $this->_values;
if (!isset($values['i'], $values['d'])) {
return static::TYPE_SAME;
}
if (empty($values['d'])) {
return static::TYPE_INSERT;
}
if (empty($values['i'])) {
return static::TYPE_DELETE;
}
return static::TYPE_CHANGE;
}
| P4Cms_Diff_Chunk::getLeft | ( | $ | index = null | ) |
Get the left-hand values for this diff chunk.
| null | int | $index | optional - the index of the value to get. |
{
return $this->_getSide(static::SIDE_LEFT, $index);
}
| P4Cms_Diff_Chunk::getMaxValueCount | ( | ) |
| P4Cms_Diff_Chunk::getRawValues | ( | ) |
Get the raw values array.
Flat for chunks of unchanged values, multi-dimensional (deleted/inserted) for chunks of changed values.
{
return $this->_values;
}
| P4Cms_Diff_Chunk::getRight | ( | $ | index = null | ) |
Get the right-hand values for this diff chunk.
| null | int | $index | optional - the index of the value to get. |
{
return $this->_getSide(static::SIDE_RIGHT, $index);
}
| P4Cms_Diff_Chunk::getSubDiff | ( | $ | index, |
| P4Cms_Diff_Options $ | options = null |
||
| ) |
Compare the left/right values at the specified index.
Useful for sub-line diffing. Splits on characters by default.
| int | $index | the index of the left/right values to get. |
| P4Cms_Diff_Options | $options | options to augment comparison behavior. |
{
// normalize options.
$options = !is_null($options) ? $options : new P4Cms_Diff_Options;
// set default split args (split on chars).
if (!$options->getSplitArgs()) {
$options->setSplitArgs(
P4Cms_Diff_Options::PATTERN_CHARS,
PREG_SPLIT_NO_EMPTY
);
}
$diff = new P4CMs_Diff;
$left = $this->getLeft($index);
$right = $this->getRight($index);
return $diff->compare($left, $right, $options);
}
| P4Cms_Diff_Chunk::isChange | ( | ) |
Check if this diff chunk is of type change.
{
return $this->getChunkType() === static::TYPE_CHANGE;
}
| P4Cms_Diff_Chunk::isDelete | ( | ) |
Check if this diff chunk is of type delete.
{
return $this->getChunkType() === static::TYPE_DELETE;
}
| P4Cms_Diff_Chunk::isInsert | ( | ) |
Check if this diff chunk is of type insert.
{
return $this->getChunkType() === static::TYPE_INSERT;
}
| P4Cms_Diff_Chunk::isSame | ( | ) |
Check if this diff chunk is of type same.
{
return $this->getChunkType() === static::TYPE_SAME;
}
| P4Cms_Diff_Chunk::isWhitespaceChange | ( | $ | semantic = true | ) |
Check if this diff chunk a whitespace only change.
| bool | $semantic | optional - defaults to true - consider semantic changes (e.g. splitting one word or joining two) a non-whitespace change. |
{
if ($this->isSame()) {
return false;
}
// use the semantic flag to control whether we collapse
// all whitespace or maintain word/line boundaries with a space.
$semantic = $semantic ? " " : "";
$left = implode($semantic, $this->getLeft());
$right = implode($semantic, $this->getRight());
// normalize whitespace.
$left = trim(preg_replace("/\s*/", $semantic, $left));
$right = trim(preg_replace("/\s*/", $semantic, $right));
return $left == $right;
}
| P4Cms_Diff_Chunk::setRawValues | ( | array $ | values | ) |
Set the raw values array.
Flat for chunks of unchanged values, multi-dimensional (deleted/inserted) for chunks of changed values.
| array | $values | optional - flat array for chunks of unchanged values multi-dimensional deleted/inserted array for chunks of changed values. |
{
$this->_values = $values;
}
P4Cms_Diff_Chunk::$_values = null [protected] |
| const P4Cms_Diff_Chunk::SIDE_LEFT = 'left' |
| const P4Cms_Diff_Chunk::SIDE_RIGHT = 'right' |
| const P4Cms_Diff_Chunk::TYPE_CHANGE = 'change' |
| const P4Cms_Diff_Chunk::TYPE_DELETE = 'delete' |
| const P4Cms_Diff_Chunk::TYPE_INSERT = 'insert' |
| const P4Cms_Diff_Chunk::TYPE_SAME = 'same' |