From: Reedy Date: Sat, 7 Apr 2012 19:00:10 +0000 (+0100) Subject: Document StringUtils X-Git-Tag: 1.31.0-rc.0~23974^2 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/?a=commitdiff_plain;h=3a6211a28ccd75f4c28d21b2b2d410eaf6460af4;p=lhc%2Fweb%2Fwiklou.git Document StringUtils Change-Id: I5a99ed602c6bf99473e2deb1c5f38faa98def30e --- diff --git a/includes/StringUtils.php b/includes/StringUtils.php index f20c548d7d..582c6cd7d9 100644 --- a/includes/StringUtils.php +++ b/includes/StringUtils.php @@ -54,6 +54,7 @@ class StringUtils { * @param $callback Callback: function to call on each match * @param $subject String * @param $flags String: regular expression flags + * @throws MWException * @return string */ static function delimiterReplaceCallback( $startDelim, $endDelim, $callback, $subject, $flags = '' ) { @@ -207,6 +208,10 @@ class StringUtils { * StringUtils::delimiterReplaceCallback() */ class Replacer { + + /** + * @return array + */ function cb() { return array( &$this, 'replace' ); } @@ -217,10 +222,18 @@ class Replacer { */ class RegexlikeReplacer extends Replacer { var $r; + + /** + * @param $r string + */ function __construct( $r ) { $this->r = $r; } + /** + * @param $matches array + * @return string + */ function replace( $matches ) { $pairs = array(); foreach ( $matches as $i => $match ) { @@ -235,12 +248,22 @@ class RegexlikeReplacer extends Replacer { * Class to perform secondary replacement within each replacement string */ class DoubleReplacer extends Replacer { + + /** + * @param $from + * @param $to + * @param $index int + */ function __construct( $from, $to, $index = 0 ) { $this->from = $from; $this->to = $to; $this->index = $index; } + /** + * @param $matches array + * @return mixed + */ function replace( $matches ) { return str_replace( $this->from, $this->to, $matches[$this->index] ); } @@ -252,11 +275,19 @@ class DoubleReplacer extends Replacer { class HashtableReplacer extends Replacer { var $table, $index; + /** + * @param $table + * @param $index int + */ function __construct( $table, $index = 0 ) { $this->table = $table; $this->index = $index; } + /** + * @param $matches array + * @return mixed + */ function replace( $matches ) { return $this->table[$matches[$this->index]]; } @@ -273,11 +304,15 @@ class ReplacementArray { /** * Create an object with the specified replacement array * The array should have the same form as the replacement array for strtr() + * @param array $data */ function __construct( $data = array() ) { $this->data = $data; } + /** + * @return array + */ function __sleep() { return array( 'data' ); } @@ -294,39 +329,61 @@ class ReplacementArray { $this->fss = false; } + /** + * @return array|bool + */ function getArray() { return $this->data; } /** * Set an element of the replacement array + * @param $from string + * @param $to stromg */ function setPair( $from, $to ) { $this->data[$from] = $to; $this->fss = false; } + /** + * @param $data array + */ function mergeArray( $data ) { $this->data = array_merge( $this->data, $data ); $this->fss = false; } + /** + * @param $other + */ function merge( $other ) { $this->data = array_merge( $this->data, $other->data ); $this->fss = false; } + /** + * @param $from string + */ function removePair( $from ) { unset($this->data[$from]); $this->fss = false; } + /** + * @param $data array + */ function removeArray( $data ) { - foreach( $data as $from => $to ) + foreach( $data as $from => $to ) { $this->removePair( $from ); + } $this->fss = false; } + /** + * @param $subject string + * @return string + */ function replace( $subject ) { if ( function_exists( 'fss_prep_replace' ) ) { wfProfileIn( __METHOD__.'-fss' ); @@ -369,8 +426,10 @@ class ExplodeIterator implements Iterator { // The current token var $current; - /** + /** * Construct a DelimIterator + * @param $delim string + * @param $s string */ function __construct( $delim, $s ) { $this->subject = $s; @@ -389,7 +448,6 @@ class ExplodeIterator implements Iterator { $this->refreshCurrent(); } - function refreshCurrent() { if ( $this->curPos === false ) { $this->current = false; @@ -410,6 +468,9 @@ class ExplodeIterator implements Iterator { return $this->curPos; } + /** + * @return string + */ function next() { if ( $this->endPos === false ) { $this->curPos = false; @@ -425,8 +486,10 @@ class ExplodeIterator implements Iterator { return $this->current; } + /** + * @return bool + */ function valid() { return $this->curPos !== false; } } -