BibTeX PARSE
version | 1 |
---|---|
package | wikindx4\core\importexport |
author | Mark Grimshaw |
__construct()
For a quick command-line test (php -f PARSEENTRIES.php) after installation, uncomment these lines:
Parse a file $parse = NEW PARSEENTRIES(); $parse->expandMacro = TRUE; // $array = array("RMP" =>"Rev., Mod. Phys."); // $parse->loadStringMacro($array); // $parse->removeDelimit = FALSE; // $parse->fieldExtract = FALSE; $parse->openBib("bib.bib"); $parse->extractEntries(); $parse->closeBib(); list($preamble, $strings, $entries, $undefinedStrings) = $parse->returnArrays(); print_r($preamble); print "\n"; print_r($strings); print "\n"; print_r($entries); print "\n\n";
// Parse a bibtex PHP string $bibtex_data = <<< END
\@STRING{three = "THREE"} \@STRING{two = "TWO"} \@string{JRNL23 = {NatLA 23 } # " " # two # " " # three}
\@article{klitzing.1, author = "v. Klitzing and Dorda and Pepper", title = "New method for high mark@sirfragalot.com accuracy determination of fine structure constant based on quantized hall resistance", volume = "45", journal = {Journal of } # JRNL23, pages = "494", citeulike-article-id = {12222 } , ignoreMe = {blah}, }
\@article { klitzing.2, author = "Klaus von Klitzing", title = "The Quantized Hall Effect", volume = "58", journal = two, pages = "519", }
END;
$parse = NEW PARSEENTRIES(); $parse->expandMacro = TRUE; // $parse->removeDelimit = FALSE; // $parse->fieldExtract = FALSE; $array = array("RMP" =>"Rev., Mod. Phys."); $parse->loadStringMacro($array); $parse->loadBibtexString($bibtex_data); $parse->extractEntries(); list($preamble, $strings, $entries, $undefinedStrings) = $parse->returnArrays(); print_r($preamble); print "\n"; print_r($strings); print "\n"; print_r($entries); print "\n\n";
closeBib()
closingDelimiter(string $val, string $delimitEnd) : int
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.
string
string
int
explodeString(string $val) : array
the character # is part of a string (i.e., is enclosed into "..." or {...} ) or defines a string concatenation as in @string{ "x # x" # ss # {xx{x}x} }
string
array
extractEntries()
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!
extractStringValue(string $string) : string
The string may be expanded with previously-defined strings
string
string
fieldSplit(string $seg) : array
string
array
fullSplit(string $entry)
Store the entry type and citation.
string
getLine() : string
string
loadBibtexString(string $bibtex_string)
string
loadStringMacro(array $macro_array)
array
openBib(string $file)
string
parseEntry(string $entry)
string
reduceFields(string $oldString)
string
removeDelimiters(string $string) : string
string
string
removeDelimitersAndExpand(string $string, boolean $inpreamble) : string
Additionally, expand macros if flag set.
string
boolean
Default is FALSE
string
returnArrays() : array
to the calling process.
array
(preamble, strings, entry, undefinedStrings)