You are here

public function PARSEENTRIES::reduceFields in Bibliography Module 7

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

Extract and format fields.

1 call to PARSEENTRIES::reduceFields()
PARSEENTRIES::fullSplit in modules/bibtexParse/PARSEENTRIES.php
Start splitting a bibtex entry into component fields. Store the entry type and citation.

File

modules/bibtexParse/PARSEENTRIES.php, line 266

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 reduceFields($oldString) {

  // 03/05/2005 G. Gardey. Do not remove all occurences, juste one
  // * correctly parse an entry ended by: somefield = {aValue}}.
  $lg = strlen($oldString);
  if ($oldString[$lg - 1] == "}" || $oldString[$lg - 1] == ")" || $oldString[$lg - 1] == ",") {
    $oldString = substr($oldString, 0, $lg - 1);
  }

  // $oldString = rtrim($oldString, "}),");.
  $split = preg_split("/=/", $oldString, 2);
  $string = $split[1];
  while ($string) {
    list($entry, $string) = $this
      ->fieldSplit($string);
    $values[] = $entry;
  }
  foreach ($values as $value) {
    $pos = strpos($oldString, $value);
    $oldString = substr_replace($oldString, '', $pos, strlen($value));
  }
  $rev = strrev(trim($oldString));
  if ($rev[0] != ',') {
    $oldString .= ',';
  }
  $keys = preg_split("/=,/", $oldString);

  // 22/08/2004 - Mark Grimshaw
  // I have absolutely no idea why this array_pop is required but it is.  Seems to always be
  // an empty key at the end after the split which causes problems if not removed.
  array_pop($keys);
  foreach ($keys as $key) {
    $value = trim(array_shift($values));
    $rev = strrev($value);

    // Remove any dangling ',' left on final field of entry.
    if ($rev[0] == ',') {
      $value = rtrim($value, ",");
    }
    if (!$value) {
      continue;
    }

    // 21/08/2004 G.Gardey -> expand macro
    // Don't remove delimiters now needs to know if the value is a string macro
    // $this->entries[$this->count][strtolower(trim($key))] = trim($this->removeDelimiters(trim($value)));
    $key = strtolower(trim($key));
    $value = trim($value);

    // Handle curly braces; this needs to be done after the bibtex entry has
    // been split into parts so it cannot go into the big transtab replacement.
    $decode_arr = array(
      // Throw away any unescaped curly braces
      // (Zotero adds lots of them, for example)
      // leave them at the start and the end of the string though.
      '@(.)(?<!\\\\){@' => '$1',
      '@(?<!\\\\)}(?!$)@' => '',
      // Decode escaped curly braces.
      '@\\\\{@' => '{',
      '@\\\\}@' => '}',
    );
    $value = preg_replace(array_keys($decode_arr), array_values($decode_arr), $value);
    $this->entries[$this->count][$key] = $value;
  }

  // Echo "**** ";print_r($this->entries[$this->count]);echo "<BR>";.
}