You are here

function PARSEENTRIES::reduceFields in Bibliography Module 5

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

File

bibtexParse/PARSEENTRIES.php, line 243

Class

PARSEENTRIES

Code

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);
    $this->entries[$this->count][$key] = $value;
  }

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