Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/3494' into develop
Browse files Browse the repository at this point in the history
Close #3494
  • Loading branch information
weierophinney committed Jan 21, 2013
2 parents 459e0bc + f299618 commit 37f74f2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 30 deletions.
6 changes: 3 additions & 3 deletions library/Zend/Filter/Word/AbstractSeparator.php
Expand Up @@ -11,16 +11,16 @@
namespace Zend\Filter\Word;

use Zend\Filter\Exception;
use Zend\Filter\PregReplace as PregReplaceFilter;
use Zend\Filter\AbstractFilter;

/**
* @category Zend
* @package Zend_Filter
*/
abstract class AbstractSeparator extends PregReplaceFilter
abstract class AbstractSeparator extends AbstractFilter
{

protected $separator = null;
protected $separator = ' ';

/**
* Constructor
Expand Down
10 changes: 5 additions & 5 deletions library/Zend/Filter/Word/CamelCaseToSeparator.php
Expand Up @@ -25,13 +25,13 @@ class CamelCaseToSeparator extends AbstractSeparator
public function filter($value)
{
if (self::hasPcreUnicodeSupport()) {
parent::setPattern(array('#(?<=(?:\p{Lu}))(\p{Lu}\p{Ll})#','#(?<=(?:\p{Ll}|\p{Nd}))(\p{Lu})#'));
parent::setReplacement(array($this->separator . '\1', $this->separator . '\1'));
$pattern = array('#(?<=(?:\p{Lu}))(\p{Lu}\p{Ll})#', '#(?<=(?:\p{Ll}|\p{Nd}))(\p{Lu})#');
$replacement = array($this->separator . '\1', $this->separator . '\1');
} else {
parent::setPattern(array('#(?<=(?:[A-Z]))([A-Z]+)([A-Z][A-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#'));
parent::setReplacement(array('\1' . $this->separator . '\2', $this->separator . '\1'));
$pattern = array('#(?<=(?:[A-Z]))([A-Z]+)([A-Z][A-z])#', '#(?<=(?:[a-z0-9]))([A-Z])#');
$replacement = array('\1' . $this->separator . '\2', $this->separator . '\1');
}

return parent::filter($value);
return preg_replace($pattern, $replacement, $value);
}
}
4 changes: 1 addition & 3 deletions library/Zend/Filter/Word/DashToSeparator.php
Expand Up @@ -24,8 +24,6 @@ class DashToSeparator extends AbstractSeparator
*/
public function filter($value)
{
$this->setPattern('#-#');
$this->setReplacement($this->separator);
return parent::filter($value);
return preg_replace('#-#', $this->separator, $value);
}
}
23 changes: 4 additions & 19 deletions library/Zend/Filter/Word/SeparatorToSeparator.php
Expand Up @@ -10,13 +10,14 @@

namespace Zend\Filter\Word;

use Zend\Filter\AbstractFilter;
use Zend\Filter\Exception;

/**
* @category Zend
* @package Zend_Filter
*/
class SeparatorToSeparator extends \Zend\Filter\PregReplace
class SeparatorToSeparator extends AbstractFilter
{
protected $searchSeparator = null;
protected $replacementSeparator = null;
Expand Down Expand Up @@ -86,28 +87,12 @@ public function getReplacementSeparator()
* @return string
*/
public function filter($value)
{
return $this->_separatorToSeparatorFilter($value);
}

/**
* Do the real work, replaces the seperator to search for with the replacement seperator
*
* Returns the replaced string
*
* @param string $value
* @return string
* @throws Exception\RuntimeException
*/
protected function _separatorToSeparatorFilter($value)
{
if ($this->searchSeparator == null) {
throw new Exception\RuntimeException('You must provide a search separator for this filter to work.');
}

$this->setPattern('#' . preg_quote($this->searchSeparator, '#') . '#');
$this->setReplacement($this->replacementSeparator);
return parent::filter($value);
$pattern = '#' . preg_quote($this->searchSeparator, '#') . '#';
return preg_replace($pattern, $this->replacementSeparator, $value);
}

}

0 comments on commit 37f74f2

Please sign in to comment.