You are here

private function Select::findParenMatch in Drupal driver for SQL Server and SQL Azure 3.0.x

Same name and namespace in other branches
  1. 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Select.php \Drupal\Driver\Database\sqlsrv\Select::findParenMatch()

Given a string find the matching parenthesis after the given point.

Parameters

string $string: The input string.

int $start_paren: The 0 indexed position of the open-paren, for which we would like to find the matching closing-paren.

Return value

int|false The 0 indexed position of the close paren.

1 call to Select::findParenMatch()
Select::addExpression in drivers/lib/Drupal/Driver/Database/sqlsrv/Select.php
Adds an expression to the list of "fields" to be SELECTed.

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Select.php, line 99

Class

Select

Namespace

Drupal\Driver\Database\sqlsrv

Code

private function findParenMatch($string, $start_paren) {
  if ($string[$start_paren] !== '(') {
    return FALSE;
  }
  $str_array = str_split(substr($string, $start_paren + 1));
  $paren_num = 1;
  foreach ($str_array as $i => $char) {
    if ($char == '(') {
      $paren_num++;
    }
    elseif ($char == ')') {
      $paren_num--;
    }
    if ($paren_num == 0) {
      return $i + $start_paren + 1;
    }
  }
  return FALSE;
}