\HTMLPurifier_Zipper

A zipper is a purely-functional data structure which contains a focus that can be efficiently manipulated. It is known as a "one-hole context". This mutable variant implements a zipper for a list as a pair of two arrays, laid out as follows:

Base list: 1 2 3 4 [ ] 6 7 8 9 Front list: 1 2 3 4 Back list: 9 8 7 6

User is expected to keep track of the "current element" and properly fill it back in as necessary. (ToDo: Maybe it's more user friendly to implicitly track the current element?)

Nota bene: the current class gets confused if you try to store NULLs in the list.

Summary

Methods
Properties
Constants
__construct()
fromArray()
toArray()
next()
advance()
prev()
delete()
done()
insertBefore()
insertAfter()
splice()
$front
$back
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$front

$front

$back

$back

Methods

__construct()

__construct(mixed  $front, mixed  $back) : mixed

Parameters

mixed $front
mixed $back

Returns

mixed —

fromArray()

fromArray(mixed  $array) : \Tuple

Creates a zipper from an array, with a hole in the 0-index position.

Parameters

mixed $array

Returns

\Tuple —

of zipper and element of first position.

toArray()

toArray(mixed  $t = NULL) : mixed

Convert zipper back into a normal array, optionally filling in the hole with a value. (Usually you should supply a $t, unless you are at the end of the array.)

Parameters

mixed $t

Returns

mixed —

next()

next( $t) : \Original

Move hole to the next element.

Parameters

$t

Element to fill hole with

Returns

\Original —

contents of new hole.

advance()

advance( $t, mixed  $n) : \Original

Iterated hole advancement.

Parameters

$t

Element to fill hole with

mixed $n

Returns

\Original —

contents of new hole, i away

prev()

prev( $t) : \Original

Move hole to the previous element

Parameters

$t

Element to fill hole with

Returns

\Original —

contents of new hole.

delete()

delete() : \Original

Delete contents of current hole, shifting hole to next element.

Returns

\Original —

contents of new hole.

done()

done() : bool

Returns true if we are at the end of the list.

Returns

bool —

insertBefore()

insertBefore(mixed  $t) : mixed

Insert element before hole.

Parameters

mixed $t

Returns

mixed —

insertAfter()

insertAfter(mixed  $t) : mixed

Insert element after hole.

Parameters

mixed $t

Returns

mixed —

splice()

splice(mixed  $t, mixed  $delete, mixed  $replacement) : mixed

Splice in multiple elements at hole. Functional specification in terms of array_splice:

$arr1 = $arr; $old1 = array_splice($arr1, $i, $delete, $replacement);

 list($z, $t) = HTMLPurifier_Zipper::fromArray($arr);
 $t = $z->advance($t, $i);
 list($old2, $t) = $z->splice($t, $delete, $replacement);
 $arr2 = $z->toArray($t);

 assert($old1 === $old2);
 assert($arr1 === $arr2);

NB: the absolute index location after this operation is unchanged!

Parameters

mixed $t
mixed $delete
mixed $replacement

Returns

mixed —