private function PoHeader::tokenizeFormula in Service Container 7.2
Same name and namespace in other branches
- 7 lib/Drupal/Component/Gettext/PoHeader.php \Drupal\Component\Gettext\PoHeader::tokenizeFormula()
Tokenize the formula.
Parameters
string $formula: A string containing the arithmetic formula.
Return value
array List of arithmetic tokens identified in the formula.
1 call to PoHeader::tokenizeFormula()
- PoHeader::parseArithmetic in lib/
Drupal/ Component/ Gettext/ PoHeader.php - Parses and sanitizes an arithmetic formula into a plural element stack.
File
- lib/
Drupal/ Component/ Gettext/ PoHeader.php, line 379 - Contains \Drupal\Component\Gettext\PoHeader.
Class
- PoHeader
- Gettext PO header handler.
Namespace
Drupal\Component\GettextCode
private function tokenizeFormula($formula) {
$formula = str_replace(" ", "", $formula);
$tokens = array();
for ($i = 0; $i < strlen($formula); $i++) {
if (is_numeric($formula[$i])) {
$num = $formula[$i];
$j = $i + 1;
while ($j < strlen($formula) && is_numeric($formula[$j])) {
$num .= $formula[$j];
$j++;
}
$i = $j - 1;
$tokens[] = $num;
}
elseif ($pos = strpos(" =<>!&|", $formula[$i])) {
$next = $formula[$i + 1];
switch ($pos) {
case 1:
case 2:
case 3:
case 4:
if ($next == '=') {
$tokens[] = $formula[$i] . '=';
$i++;
}
else {
$tokens[] = $formula[$i];
}
break;
case 5:
if ($next == '&') {
$tokens[] = '&&';
$i++;
}
else {
$tokens[] = $formula[$i];
}
break;
case 6:
if ($next == '|') {
$tokens[] = '||';
$i++;
}
else {
$tokens[] = $formula[$i];
}
break;
}
}
else {
$tokens[] = $formula[$i];
}
}
return $tokens;
}