Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
HTMLPurifier_Zipper Class Reference

Public Member Functions

 __construct ($front, $back)
 
 advance ($t, $n)
 Iterated hole advancement.
 
 delete ()
 Delete contents of current hole, shifting hole to next element.
 
 done ()
 Returns true if we are at the end of the list.
 
 insertAfter ($t)
 Insert element after hole.
 
 insertBefore ($t)
 Insert element before hole.
 
 next ($t)
 Move hole to the next element.
 
 prev ($t)
 Move hole to the previous element.
 
 splice ($t, $delete, $replacement)
 Splice in multiple elements at hole.
 
 toArray ($t=NULL)
 Convert zipper back into a normal array, optionally filling in the hole with a value.
 

Static Public Member Functions

static fromArray ($array)
 Creates a zipper from an array, with a hole in the 0-index position.
 

Public Attributes

 $back
 
 $front
 

Member Function Documentation

◆ advance()

HTMLPurifier_Zipper::advance ( $t,
$n )

Iterated hole advancement.

Parameters
$tElement to fill hole with
$iHow many forward to advance hole
Return values
Originalcontents of new hole, i away

◆ delete()

HTMLPurifier_Zipper::delete ( )

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

Return values
Originalcontents of new hole.

◆ done()

HTMLPurifier_Zipper::done ( )

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

Return values
bool

◆ fromArray()

static HTMLPurifier_Zipper::fromArray ( $array)
static

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

Parameters
Arrayto zipper-ify.
Return values
Tupleof zipper and element of first position.

◆ insertAfter()

HTMLPurifier_Zipper::insertAfter ( $t)

Insert element after hole.

Parameters
Elementto insert

◆ insertBefore()

HTMLPurifier_Zipper::insertBefore ( $t)

Insert element before hole.

Parameters
Elementto insert

◆ next()

HTMLPurifier_Zipper::next ( $t)

Move hole to the next element.

Parameters
$tElement to fill hole with
Return values
Originalcontents of new hole.

◆ prev()

HTMLPurifier_Zipper::prev ( $t)

Move hole to the previous element.

Parameters
$tElement to fill hole with
Return values
Originalcontents of new hole.

◆ splice()

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

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
Currentcontents of hole.

◆ toArray()

HTMLPurifier_Zipper::toArray ( $t = NULL)

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.)


The documentation for this class was generated from the following file: