support quoting commodity symbols
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sat, 17 Aug 2019 21:35:38 +0000 (15:35 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sat, 17 Aug 2019 21:35:38 +0000 (15:35 -0600)
lib/App/HomeBank2Ledger/Formatter/Ledger.pm

index 677facb02e72a5924617ca4e726424921d9497f7..71d9020249983e6943620bb52f379daa32ed04ba 100644 (file)
@@ -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;
 }
This page took 0.023332 seconds and 4 git commands to generate.