Commit 17ca07fd by Alexander Makarov

More consistent usage of MessageFormatter::tokenizePattern

parent b21fd298
...@@ -137,7 +137,7 @@ class MessageFormatter extends Component ...@@ -137,7 +137,7 @@ class MessageFormatter extends Component
} }
// replace named arguments // replace named arguments
if (($tokens = $this->tokenizePattern($pattern)) === false) { if (($tokens = self::tokenizePattern($pattern)) === false) {
$this->_errorCode = -1; $this->_errorCode = -1;
$this->_errorMessage = "Message pattern is invalid."; $this->_errorMessage = "Message pattern is invalid.";
return false; return false;
...@@ -187,7 +187,7 @@ class MessageFormatter extends Component ...@@ -187,7 +187,7 @@ class MessageFormatter extends Component
*/ */
private function replaceNamedArguments($pattern, $givenParams, &$resultingParams, &$map = []) private function replaceNamedArguments($pattern, $givenParams, &$resultingParams, &$map = [])
{ {
if (($tokens = $this->tokenizePattern($pattern)) === false) { if (($tokens = self::tokenizePattern($pattern)) === false) {
return false; return false;
} }
foreach($tokens as $i => $token) { foreach($tokens as $i => $token) {
...@@ -214,7 +214,7 @@ class MessageFormatter extends Component ...@@ -214,7 +214,7 @@ class MessageFormatter extends Component
if (!isset($token[2])) { if (!isset($token[2])) {
return false; return false;
} }
$subtokens = $this->tokenizePattern($token[2]); $subtokens = self::tokenizePattern($token[2]);
$c = count($subtokens); $c = count($subtokens);
for ($k = 0; $k + 1 < $c; $k++) { for ($k = 0; $k + 1 < $c; $k++) {
if (is_array($subtokens[$k]) || !is_array($subtokens[++$k])) { if (is_array($subtokens[$k]) || !is_array($subtokens[++$k])) {
...@@ -239,7 +239,7 @@ class MessageFormatter extends Component ...@@ -239,7 +239,7 @@ class MessageFormatter extends Component
*/ */
protected function fallbackFormat($pattern, $args, $locale) protected function fallbackFormat($pattern, $args, $locale)
{ {
if (($tokens = $this->tokenizePattern($pattern)) === false) { if (($tokens = self::tokenizePattern($pattern)) === false) {
$this->_errorCode = -1; $this->_errorCode = -1;
$this->_errorMessage = "Message pattern is invalid."; $this->_errorMessage = "Message pattern is invalid.";
return false; return false;
...@@ -261,7 +261,7 @@ class MessageFormatter extends Component ...@@ -261,7 +261,7 @@ class MessageFormatter extends Component
* @param string $pattern patter to tokenize * @param string $pattern patter to tokenize
* @return array|bool array of tokens or false on failure * @return array|bool array of tokens or false on failure
*/ */
private function tokenizePattern($pattern) private static function tokenizePattern($pattern)
{ {
$depth = 1; $depth = 1;
if (($start = $pos = mb_strpos($pattern, '{')) === false) { if (($start = $pos = mb_strpos($pattern, '{')) === false) {
...@@ -340,7 +340,7 @@ class MessageFormatter extends Component ...@@ -340,7 +340,7 @@ class MessageFormatter extends Component
if (!isset($token[2])) { if (!isset($token[2])) {
return false; return false;
} }
$select = static::tokenizePattern($token[2]); $select = self::tokenizePattern($token[2]);
$c = count($select); $c = count($select);
$message = false; $message = false;
for ($i = 0; $i + 1 < $c; $i++) { for ($i = 0; $i + 1 < $c; $i++) {
...@@ -368,7 +368,7 @@ class MessageFormatter extends Component ...@@ -368,7 +368,7 @@ class MessageFormatter extends Component
if (!isset($token[2])) { if (!isset($token[2])) {
return false; return false;
} }
$plural = static::tokenizePattern($token[2]); $plural = self::tokenizePattern($token[2]);
$c = count($plural); $c = count($plural);
$message = false; $message = false;
$offset = 0; $offset = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment