diff -r 000000000000 -r 4eba9c11703f web/Zend/Filter/StringTrim.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/web/Zend/Filter/StringTrim.php Mon Dec 13 18:29:26 2010 +0100 @@ -0,0 +1,124 @@ +toArray(); + } else if (!is_array($options)) { + $options = func_get_args(); + $temp['charlist'] = array_shift($options); + $options = $temp; + } + + if (array_key_exists('charlist', $options)) { + $this->setCharList($options['charlist']); + } + } + + /** + * Returns the charList option + * + * @return string|null + */ + public function getCharList() + { + return $this->_charList; + } + + /** + * Sets the charList option + * + * @param string|null $charList + * @return Zend_Filter_StringTrim Provides a fluent interface + */ + public function setCharList($charList) + { + $this->_charList = $charList; + return $this; + } + + /** + * Defined by Zend_Filter_Interface + * + * Returns the string $value with characters stripped from the beginning and end + * + * @param string $value + * @return string + */ + public function filter($value) + { + if (null === $this->_charList) { + return $this->_unicodeTrim((string) $value); + } else { + return $this->_unicodeTrim((string) $value, $this->_charList); + } + } + + /** + * Unicode aware trim method + * Fixes a PHP problem + * + * @param string $value + * @param string $charlist + * @return string + */ + protected function _unicodeTrim($value, $charlist = '\\\\s') + { + $chars = preg_replace( + array( '/[\^\-\]\\\]/S', '/\\\{4}/S', '/\//'), + array( '\\\\\\0', '\\', '\/' ), + $charlist + ); + + $pattern = '^[' . $chars . ']*|[' . $chars . ']*$'; + return preg_replace("/$pattern/sSD", '', $value); + } +}