You are here

public function PARSEENTRIES::closingDelimiter in Bibliography Module 7

Same name and namespace in other branches
  1. 5 bibtexParse/PARSEENTRIES.php \PARSEENTRIES::closingDelimiter()
  2. 6.2 modules/bibtexParse/PARSEENTRIES.php \PARSEENTRIES::closingDelimiter()
  3. 6 bibtexParse/PARSEENTRIES.php \PARSEENTRIES::closingDelimiter()
  4. 7.3 plugins/biblio_style/bibtex/PARSEENTRIES.php \PARSEENTRIES::closingDelimiter()
  5. 7.2 modules/bibtexParse/PARSEENTRIES.php \PARSEENTRIES::closingDelimiter()

This function receives a string and a closing delimiter '}' or ')' and looks for the position of the closing delimiter taking into account the following Bibtex rules:

  • Inside the braces, there can arbitrarily nested pairs of braces, but braces must also be balanced inside quotes!
  • Inside quotes, to place the " character it is not sufficient to simply escape with \": Quotes must be placed inside braces.
1 call to PARSEENTRIES::closingDelimiter()
PARSEENTRIES::extractEntries in modules/bibtexParse/PARSEENTRIES.php
This function extract entries taking into account how comments are defined in BibTeX. BibTeX splits the file in two areas: inside an entry and outside an entry, the delimitation being indicated by the presence of a @ sign. When this character is met,…

File

modules/bibtexParse/PARSEENTRIES.php, line 444

Class

PARSEENTRIES
// Parse a file $parse = NEW PARSEENTRIES(); $parse->expandMacro = TRUE; // $array = array("RMP" =>"Rev., Mod. Phys."); // $parse->loadStringMacro($array); // $parse->removeDelimit = FALSE; // …

Code

public function closingDelimiter($val, $delimitEnd) {

  // Echo "####>$delimitEnd $val<BR>";.
  $openquote = $bracelevel = $i = $j = 0;
  while ($i < strlen($val)) {

    // A '"' found at brace level 0 defines a value such as "ss{\"o}ss".
    if ($val[$i] == '"' && !$bracelevel) {
      $openquote = !$openquote;
    }
    elseif ($val[$i] == '{') {
      $bracelevel++;
    }
    elseif ($val[$i] == '}') {
      $bracelevel--;
    }
    if ($val[$i] == $delimitEnd && !$openquote && !$bracelevel) {
      return $i;
    }
    $i++;
  }

  // Echo "--> $bracelevel, $openquote";.
  return 0;
}