You are here

function _name_format_closing_bracket_position in Name Field 6

Same name and namespace in other branches
  1. 7 includes/name.parser.inc \_name_format_closing_bracket_position()

Helper function to put out the first matched bracket position.

Accepts strings in the format, ^ marks the matched bracket. '(xxx^)xxx(xxxx)xxxx' or '(xxx(xxx(xxxx))xxx^)'

1 call to _name_format_closing_bracket_position()
_name_format in includes/name.parser.inc

File

includes/name.parser.inc, line 290
Provides the functionality and information about the Name module name parsing engine.

Code

function _name_format_closing_bracket_position($string) {

  // Simplify the string by removing escaped brackets.
  $depth = 0;
  $string = str_replace(array(
    '\\(',
    '\\)',
  ), array(
    '__',
    '__',
  ), $string);
  for ($i = 0; $i < strlen($string); $i++) {
    $char = $string[$i];
    if ($char == '(') {
      $depth++;
    }
    elseif ($char == ')') {
      $depth--;
      if ($depth == 0) {
        return $i;
      }
    }
  }
  return FALSE;
}