Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PoHeader.php

function 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 376

Class

PoHeader
Gettext PO header handler.

Namespace

Drupal\Component\Gettext

Code

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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal