From dcc6bb38342f788f336b8be59b552bcb84e25afe Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Sat, 29 Jan 2022 20:53:29 -0700 Subject: [PATCH 1/1] fix formatting symbols with special characters --- lib/App/HomeBank2Ledger/Formatter/Ledger.pm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm index c6fa556..bd72459 100644 --- a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm +++ b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm @@ -25,6 +25,7 @@ my %STATUS_SYMBOLS = ( cleared => '*', pending => '!', ); +my $SYMBOL = qr![^\s\d.,;:?\!\-+*/^&|=\<\>\[\]\(\)\{\}\@]+!; sub _croak { require Carp; Carp::croak(@_) } @@ -343,6 +344,13 @@ sub _quote_string { return "\"$str\""; } +sub _format_symbol { + my $self = shift; + my $str = shift; + return $self->_quote_string($str) if $str !~ /^${SYMBOL}$/; + return $str; +} + sub _format_amount { my $self = shift; my $amount = shift; @@ -357,9 +365,7 @@ sub _format_amount { $num .= $commodity->{dchar} . $fraction; } - my $symbol = $commodity->{symbol}; - $symbol = $self->_quote_string($symbol) if $symbol =~ /[0-9\s]/; - + my $symbol = $self->_format_symbol($commodity->{symbol}); $num = $commodity->{syprf} ? "$symbol $num" : "$num $symbol"; return $num; -- 2.43.0