You are here

protected function QueryPathCssEventHandler::parseAnB in QueryPath 6

Same name and namespace in other branches
  1. 7.3 QueryPath/CssEventHandler.php \QueryPathCssEventHandler::parseAnB()
  2. 7.2 QueryPath/CssEventHandler.php \QueryPathCssEventHandler::parseAnB()
1 call to QueryPathCssEventHandler::parseAnB()
QueryPathCssEventHandler::pseudoClass in QueryPath/CssEventHandler.php

File

QueryPath/CssEventHandler.php, line 578

Class

QueryPathCssEventHandler

Code

protected function parseAnB($rule) {
  if ($rule == 'even') {
    return array(
      2,
      0,
    );
  }
  elseif ($rule == 'odd') {
    return array(
      2,
      1,
    );
  }
  elseif ($rule == 'n') {
    return array(
      1,
      0,
    );
  }
  elseif (is_numeric($rule)) {
    return array(
      0,
      (int) $rule,
    );
  }
  $rule = explode('n', $rule);
  if (count($rule) == 0) {
    throw new CssParseException("nth-child value is invalid.");
  }
  $aVal = (int) trim($rule[0]);
  $bVal = !empty($rule[1]) ? (int) trim($rule[1]) : 0;
  return array(
    $aVal,
    $bVal,
  );
}