From 4a067535b63531a23bab32d71fa6db26cfb4521b Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Fri, 2 Sep 2016 15:14:06 +0200 Subject: [PATCH] adds useful method removeField --- bibtexbrowser-test.php | 8 ++++++++ bibtexbrowser.php | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/bibtexbrowser-test.php b/bibtexbrowser-test.php index 51e8b1e..446fc8e 100755 --- a/bibtexbrowser-test.php +++ b/bibtexbrowser-test.php @@ -562,6 +562,14 @@ class BTBTest extends PHPUnit_Framework_TestCase { unlink($test_file); } + function test_removeField() { + $btb = $this->createDB(); + $first_entry=$btb->getEntryByKey('aKey'); + $this->assertTrue($first_entry->hasField('author')); + $first_entry->removeField('author'); + $this->assertFalse($first_entry->hasField('author')); + } + } // end class ?> diff --git a/bibtexbrowser.php b/bibtexbrowser.php index 1634c82..f657a92 100755 --- a/bibtexbrowser.php +++ b/bibtexbrowser.php @@ -1207,6 +1207,13 @@ class BibEntry { } return $value; } + + /** removes a field from this bibtex entry */ + function removeField($name) { + $name = strtolower($name); + unset($this->raw_fields[$name]); + unset($this->fields[$name]); + } /** Sets a field of this bib entry. */ function setField($name, $value) {