You are here

private function Connection::findParenMatch in Drupal driver for SQL Server and SQL Azure 4.0.x

Same name and namespace in other branches
  1. 4.2.x src/Driver/Database/sqlsrv/Connection.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Connection::findParenMatch()
  2. 3.1.x src/Driver/Database/sqlsrv/Connection.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Connection::findParenMatch()
  3. 4.1.x src/Driver/Database/sqlsrv/Connection.php \Drupal\sqlsrv\Driver\Database\sqlsrv\Connection::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 Connection::findParenMatch()
Connection::query in src/Driver/Database/sqlsrv/Connection.php
Executes a query string against the database.

File

src/Driver/Database/sqlsrv/Connection.php, line 739

Class

Connection
Sqlsvr implementation of \Drupal\Core\Database\Connection.

Namespace

Drupal\sqlsrv\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;
}