Skip Menu |
 

This queue is for tickets about the BibTeX-Parser CPAN distribution.

Report information
The Basics
Id: 47977
Status: resolved
Priority: 0/
Queue: BibTeX-Parser

People
Owner: Nobody in particular
Requestors: smueller [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.21
Fixed in: (no value)



Subject: [PATCH] Remember raw input bibtex
Download (untitled) / with headers
text/plain 434b
Hi Gerhard, attached is a patch that makes the parser remember an entry's raw input BibTeX. It's quite straightforward and would be VERY useful for my project. Note that remembering an entry's raw BibTeX is different from simply caching the entire input stream since slicing up the input into different entries is already non-trivial. I'd really appreciate if you could apply this patch for the next release. Best regards, Steffen
Subject: raw_bibtex.patch
Download raw_bibtex.patch
text/x-diff 1.4k
--- lib_old/BibTeX/Parser.pm 2009-07-17 15:54:58.000000000 +0200 +++ lib/BibTeX/Parser.pm 2009-07-17 16:25:10.000000000 +0200 @@ -113,8 +113,9 @@ if (/@($re_name)/cgo) { my $type = uc $1; $current_entry->type( $type ); + my $start_pos = pos($_) - length($type) - 1; - # read rest of entry (matches braces + # read rest of entry (matches braces) my $bracelevel = 0; $bracelevel += tr/\{/\{/; #count braces $bracelevel -= tr/\}/\}/; @@ -127,6 +128,12 @@ pos($_) = $position; } + # Remember raw bibtex code + my $raw = substr($_, $start_pos); + $raw =~ s/^\s+//; + $raw =~ s/\s+$//; + $current_entry->raw_bibtex($raw); + my $pos = pos $_; tr/\n/ /; pos($_) = $pos; --- lib_old/BibTeX/Parser/Entry.pm 2009-07-17 15:54:58.000000000 +0200 +++ lib/BibTeX/Parser/Entry.pm 2009-07-17 16:11:41.000000000 +0200 @@ -53,6 +53,7 @@ $fields{_type} = uc($type); $fields{_key} = $key; $fields{_parse_ok} = $parse_ok; + $fields{_raw} = ''; return bless \%fields, $class; } @@ -234,6 +235,22 @@ return $value; } + +=head2 raw_bibtex + +Return raw BibTeX entry (if available). + +=cut + +sub raw_bibtex { + my $self = shift; + if (@_) { + $self->{_raw} = shift; + } + return $self->{_raw}; +} + + =head1 AUTHOR Gerhard Gossen, C<< <gerhard.gossen at googlemail.com> >>


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.