You are here

function _potx_skip_args in Translation template extractor 8

Same name and namespace in other branches
  1. 6.3 potx.inc \_potx_skip_args()
  2. 7.3 potx.inc \_potx_skip_args()
  3. 7 potx.inc \_potx_skip_args()
  4. 7.2 potx.inc \_potx_skip_args()

Helper to move past t() and format_plural() arguments in search of context.

Parameters

int $here: The token before the start of the arguments.

1 call to _potx_skip_args()
_potx_find_context in ./potx.inc
Helper to find the value for 'context' on t() and format_plural().

File

./potx.inc, line 1407
Extraction API used by the web and command line interface.

Code

function _potx_skip_args($here) {
  global $_potx_tokens;
  $nesting = 0;

  // Continue until we reach a semicolon or the end of the function call.
  while ($_potx_tokens[$here] !== ';' && $nesting >= -1) {
    if (!is_array($_potx_tokens[$here])) {
      if ($_potx_tokens[$here] == ')' || $_potx_tokens[$here] == ']') {
        $nesting--;
      }
      if ($_potx_tokens[$here] == '(' || $_potx_tokens[$here] == '[') {
        $nesting++;
      }
    }

    // If we reach a comma on the same nesting level, or the end of the function
    // call, we have skipped past the function arguments.
    if ($_potx_tokens[$here] == ',' && $nesting == 0 || $_potx_tokens[$here] == ')' && $nesting == -1) {
      break;
    }
    $here++;
  }

  // Generate an error if we encounter a semicolon before the end of the
  // function call.
  if ($_potx_tokens[$here] === ';' && $nesting !== -1) {
    potx_status('error', t('Unexpected ;'));
  }

  // If we run out of nesting, it means we reached the end of the function call,
  // so we skipped the arguments but did not find meat for looking at the
  // specified context.
  return $nesting == 0 ? $here : FALSE;
}