public function PARSEENTRIES::extractEntries in Bibliography Module 7
Same name and namespace in other branches
- 5 bibtexParse/PARSEENTRIES.php \PARSEENTRIES::extractEntries()
- 6.2 modules/bibtexParse/PARSEENTRIES.php \PARSEENTRIES::extractEntries()
- 6 bibtexParse/PARSEENTRIES.php \PARSEENTRIES::extractEntries()
- 7.3 plugins/biblio_style/bibtex/PARSEENTRIES.php \PARSEENTRIES::extractEntries()
- 7.2 modules/bibtexParse/PARSEENTRIES.php \PARSEENTRIES::extractEntries()
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, BibTeX expects to find an entry. Before that sign, and after an entry, everything is considered a comment!
File
- modules/
bibtexParse/ PARSEENTRIES.php, line 500
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 extractEntries() {
$inside = $possibleEntryStart = FALSE;
$entry = "";
while ($line = $this
->getLine()) {
if ($possibleEntryStart) {
$line = $possibleEntryStart . $line;
}
if (!$inside && strchr($line, "@")) {
// Throw all characters before the '@'.
$line = strstr($line, '@');
if (!strchr($line, "{") && !strchr($line, "(")) {
$possibleEntryStart = $line;
}
elseif (preg_match("/@.*([{(])/U", preg_quote($line), $matches)) {
$inside = TRUE;
if ($matches[1] == '{') {
$delimitEnd = '}';
}
else {
$delimitEnd = ')';
}
$possibleEntryStart = FALSE;
}
}
if ($inside) {
$entry .= " " . $line;
if ($j = $this
->closingDelimiter($entry, $delimitEnd)) {
// All characters after the delimiter are thrown but the remaining
// characters must be kept since they may start the next entry !!!
$lastLine = substr($entry, $j + 1);
$entry = substr($entry, 0, $j + 1);
// Strip excess whitespaces from the entry.
$entry = preg_replace('/\\s\\s+/', ' ', $entry);
$this
->parseEntry($entry);
$entry = strchr($lastLine, "@");
if ($entry) {
$inside = TRUE;
}
else {
$inside = FALSE;
}
}
}
}
}