-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9d7386b
commit 8afd612
Showing
6 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
""" | ||
fileio_load(file; check) | ||
fileio_load(stream; check) | ||
The FileIO interface to import a BibTeX file or parse a BibTeX string and convert it to the internal bibliography format. | ||
The `check` keyword argument can be set to `:none` (or `nothing`), `:warn`, or `:error` to raise appropriate logs. | ||
""" | ||
function fileio_load(file::FileIO.File{FileIO.format"BIB"}; check = :error) | ||
BibParser.parse_file(file.filename; check) | ||
end | ||
|
||
function fileio_load(stream::FileIO.Stream{FileIO.format"BIB"}; check = :error) | ||
BibParser.parse_entry(read(stream, String); check) | ||
end | ||
|
||
""" | ||
fileio_save(file, data) | ||
fileio_save(stream, data) | ||
Export a bibliography as a BibTeX string to a file or stream. | ||
""" | ||
function fileio_save(file::FileIO.File{FileIO.format"BIB"}, data) | ||
open(file, "w") do f | ||
write(f, export_bibtex(data)) | ||
end | ||
end | ||
|
||
function fileio_save(stream::FileIO.Stream{FileIO.format"BIB"}, data) | ||
write(stream, export_bibtex(data)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[deps] | ||
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" | ||
ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@testset "FileIO interface functions." begin | ||
F = FileIO.File{FileIO.format"BIB"} | ||
S = FileIO.Stream{FileIO.format"BIB"} | ||
|
||
# Load, export and reload as file. | ||
let | ||
bib = Bibliography.fileio_load(F("test.bib")) | ||
Bibliography.fileio_save(F("test-fileio.bib"), bib) | ||
bib2 = Bibliography.fileio_load(F("test-fileio.bib")) | ||
@test_broken bib == bib2 | ||
rm("test-fileio.bib") | ||
end | ||
|
||
# Load, export and reload as stream. | ||
let | ||
bib = open("test.bib") do f | ||
Bibliography.fileio_load(S(f)) | ||
end | ||
open("test-fileio.bib", "w") do f | ||
Bibliography.fileio_save(S(f), bib) | ||
end | ||
bib2 = open("test-fileio.bib") do f | ||
Bibliography.fileio_load(S(f)) | ||
end | ||
@test_broken bib == bib2 | ||
rm("test-fileio.bib") | ||
end | ||
end |