private function PoHeader::tokenizeFormula in Drupal 8
Same name and namespace in other branches
- 9 core/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 core/
lib/ Drupal/ Component/ Gettext/ PoHeader.php - Parses and sanitizes an arithmetic formula into a plural element stack.
File
- core/
lib/ Drupal/ Component/ Gettext/ PoHeader.php, line 374
Class
- PoHeader
- Gettext PO header handler.
Namespace
Drupal\Component\GettextCode
private function tokenizeFormula($formula) {
$formula = str_replace(" ", "", $formula);
$tokens = [];
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;
}