From f6d65e533c62f6deb21342d4901ece24497b433e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Thu, 4 Jun 2015 07:31:04 +0200 Subject: Update to MediaWiki 1.25.1 --- includes/libs/ExplodeIterator.php | 116 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 includes/libs/ExplodeIterator.php (limited to 'includes/libs/ExplodeIterator.php') diff --git a/includes/libs/ExplodeIterator.php b/includes/libs/ExplodeIterator.php new file mode 100644 index 00000000..3b34d9bc --- /dev/null +++ b/includes/libs/ExplodeIterator.php @@ -0,0 +1,116 @@ +subject = $subject; + $this->delim = $delim; + + // Micro-optimisation (theoretical) + $this->subjectLength = strlen( $subject ); + $this->delimLength = strlen( $delim ); + + $this->rewind(); + } + + public function rewind() { + $this->curPos = 0; + $this->endPos = strpos( $this->subject, $this->delim ); + $this->refreshCurrent(); + } + + public function refreshCurrent() { + if ( $this->curPos === false ) { + $this->current = false; + } elseif ( $this->curPos >= $this->subjectLength ) { + $this->current = ''; + } elseif ( $this->endPos === false ) { + $this->current = substr( $this->subject, $this->curPos ); + } else { + $this->current = substr( $this->subject, $this->curPos, $this->endPos - $this->curPos ); + } + } + + public function current() { + return $this->current; + } + + /** + * @return int|bool Current position or boolean false if invalid + */ + public function key() { + return $this->curPos; + } + + /** + * @return string + */ + public function next() { + if ( $this->endPos === false ) { + $this->curPos = false; + } else { + $this->curPos = $this->endPos + $this->delimLength; + if ( $this->curPos >= $this->subjectLength ) { + $this->endPos = false; + } else { + $this->endPos = strpos( $this->subject, $this->delim, $this->curPos ); + } + } + $this->refreshCurrent(); + + return $this->current; + } + + /** + * @return bool + */ + public function valid() { + return $this->curPos !== false; + } +} -- cgit v1.2.3-54-g00ecf