X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fhomebank2ledger;a=blobdiff_plain;f=lib%2FFile%2FHomeBank.pm;h=7d29ada68dfa09d4acc4459090b60af58ec6bfc2;hp=31ca39d097ea8ab771418d117d7f37085fdec86c;hb=809727a3740f74a8836fa49dbf24bd672c58d39e;hpb=2752b344bcd543f73fceea80dcdbb11c20dc592a diff --git a/lib/File/HomeBank.pm b/lib/File/HomeBank.pm index 31ca39d..7d29ada 100644 --- a/lib/File/HomeBank.pm +++ b/lib/File/HomeBank.pm @@ -30,15 +30,13 @@ use App::HomeBank2Ledger::Util qw(commify); use Exporter qw(import); use Scalar::Util qw(refaddr); use Time::Piece; +use XML::Entities; use XML::Parser::Lite; our $VERSION = '9999.999'; # VERSION our @EXPORT_OK = qw(parse_string parse_file); -sub _croak { require Carp; Carp::croak(@_) } -sub _usage { _croak("Usage: @_\n") } - my %ACCOUNT_TYPES = ( 0 => 'none', 1 => 'bank', @@ -104,6 +102,9 @@ my %TRANSACTION_PAYMODES = ( 11 => 'directdebit', ); +sub _croak { require Carp; Carp::croak(@_) } +sub _usage { _croak("Usage: @_\n") } + =method new $homebank = File::HomeBank->new(string => $str); @@ -415,7 +416,7 @@ sub find_transaction_transfer_pair { $transations = $homebank->sorted_transactions; -Get an arrayref of transactions sorted by date (earliest first). +Get an arrayref of transactions sorted by date (oldest first). =cut @@ -532,6 +533,12 @@ sub parse_string { shift; my $node = shift; my %attr = @_; + + # decode all attribute values + for my $key (keys %attr) { + $attr{$key} = _decode_xml_entities($attr{$key}); + } + if ($node eq 'properties') { $attr{currency} = delete $attr{curr} if $attr{curr}; %properties = %attr; @@ -568,11 +575,15 @@ sub parse_string { $attr{flags}{$name} = $flags & (1 << $shift) ? 1 : 0; } + for my $bnum (0 .. 12) { + $attr{budget_amounts}[$bnum] = delete $attr{"b$bnum"} if $attr{"b$bnum"}; + } + push @categories, \%attr; } elsif ($node eq 'ope') { # transaction - $attr{paymode} = $TRANSACTION_PAYMODES{$attr{paymode} || ''} || 'unknown'; - $attr{status} = $TRANSACTION_STATUSES{delete $attr{st}} || 'unknown'; + $attr{paymode} = $TRANSACTION_PAYMODES{$attr{paymode} || ''} || 'unknown'; + $attr{status} = $TRANSACTION_STATUSES{delete $attr{st} || ''} || 'unknown'; $attr{transfer_key} = delete $attr{kxfer} if $attr{kxfer}; $attr{split_amount} = delete $attr{samt} if $attr{samt}; @@ -603,6 +614,14 @@ sub parse_string { }; } +sub _decode_xml_entities { + my $str = shift; + # decoding entities can be extremely slow, so don't bother if it doesn't look like there are any + # entities to decode + return $str if $str !~ /&(?:#\d+)|[A-Za-z0-9]+;/; + return XML::Entities::decode('all', $str); +} + sub _rdn_to_unix_epoch { my $rdn = shift; my $jan01_1970 = 719163;