]> Dogcows Code - chaz/homebank2ledger/commitdiff
fix formatting symbols with special characters
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 30 Jan 2022 03:53:29 +0000 (20:53 -0700)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 30 Jan 2022 03:53:29 +0000 (20:53 -0700)
lib/App/HomeBank2Ledger/Formatter/Ledger.pm

index c6fa55668a6eb4ec02ab6a3b58117965c638124e..bd7245944f6b47c2740df330503bb714da698978 100644 (file)
@@ -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;
This page took 0.030107 seconds and 4 git commands to generate.