HTMLPurifier/Zipper.php Quellcode

Zipper.php
gehe zur Dokumentation dieser Datei
1 <?php
2 
22 {
23  public $front, $back;
24 
25  public function __construct($front, $back) {
26  $this->front = $front;
27  $this->back = $back;
28  }
29 
36  static public function fromArray($array) {
37  $z = new self(array(), array_reverse($array));
38  $t = $z->delete(); // delete the "dummy hole"
39  return array($z, $t);
40  }
41 
47  public function toArray($t = NULL) {
48  $a = $this->front;
49  if ($t !== NULL) $a[] = $t;
50  for ($i = count($this->back)-1; $i >= 0; $i--) {
51  $a[] = $this->back[$i];
52  }
53  return $a;
54  }
55 
61  public function next($t) {
62  if ($t !== NULL) array_push($this->front, $t);
63  return empty($this->back) ? NULL : array_pop($this->back);
64  }
65 
72  public function advance($t, $n) {
73  for ($i = 0; $i < $n; $i++) {
74  $t = $this->next($t);
75  }
76  return $t;
77  }
78 
84  public function prev($t) {
85  if ($t !== NULL) array_push($this->back, $t);
86  return empty($this->front) ? NULL : array_pop($this->front);
87  }
88 
94  public function delete() {
95  return empty($this->back) ? NULL : array_pop($this->back);
96  }
97 
102  public function done() {
103  return empty($this->back);
104  }
105 
110  public function insertBefore($t) {
111  if ($t !== NULL) array_push($this->front, $t);
112  }
113 
118  public function insertAfter($t) {
119  if ($t !== NULL) array_push($this->back, $t);
120  }
121 
142  public function splice($t, $delete, $replacement) {
143  // delete
144  $old = array();
145  $r = $t;
146  for ($i = $delete; $i > 0; $i--) {
147  $old[] = $r;
148  $r = $this->delete();
149  }
150  // insert
151  for ($i = count($replacement)-1; $i >= 0; $i--) {
152  $this->insertAfter($r);
153  $r = $replacement[$i];
154  }
155  return array($old, $r);
156  }
157 }




Korrekturen, Hinweise und Ergänzungen

Bitte scheuen Sie sich nicht und melden Sie, was auf dieser Seite sachlich falsch oder irreführend ist, was ergänzt werden sollte, was fehlt usw. Dazu bitte oben aus dem Menü Seite den Eintrag Support Forum wählen. Es ist eine kostenlose Anmeldung erforderlich, um Anmerkungen zu posten. Unpassende Postings, Spam usw. werden kommentarlos entfernt.