From: Charles McGarvey Date: Sat, 17 Aug 2019 21:35:38 +0000 (-0600) Subject: support quoting commodity symbols X-Git-Tag: v0.005~3 X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fhomebank2ledger;a=commitdiff_plain;h=9a270ef9470db7ca110c2ad60fcd13f8674fdf63;hp=2cb8cd6b61921ef8f051f9066411deb4c829b68d support quoting commodity symbols --- diff --git a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm index 677facb..71d9020 100644 --- a/lib/App/HomeBank2Ledger/Formatter/Ledger.pm +++ b/lib/App/HomeBank2Ledger/Formatter/Ledger.pm @@ -269,6 +269,13 @@ sub _format_string { return $str; } +sub _quote_string { + my $self = shift; + my $str = shift; + $str =~ s/"/\\"/g; + return "\"$str\""; +} + sub _format_amount { my $self = shift; my $amount = shift; @@ -279,7 +286,10 @@ sub _format_amount { my $num = join($commodity->{dchar}, commify($whole, $commodity->{gchar}), $fraction); - $num = $commodity->{syprf} ? "$commodity->{symbol} $num" : "$num $commodity->{symbol}"; + my $symbol = $commodity->{symbol}; + $symbol = $self->_quote_string($symbol) if $symbol =~ /[0-9\s]/; + + $num = $commodity->{syprf} ? "$symbol $num" : "$num $symbol"; return $num; }