You are here

private function Select::findParenMatch in Drupal driver for SQL Server and SQL Azure 8

Same name and namespace in other branches
  1. 3.0.x 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 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 92
Definition of Drupal\Driver\Database\sqlsrv\Select

Class

Select

Namespace

Drupal\Driver\Database\sqlsrv

Code

private function findParenMatch($string, $start_paren) {
  $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;
    }
  }
}