aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2020-11-13 01:51:49 +0100
committerJohn Ankarström <john@ankarstrom.se>2020-11-13 01:51:49 +0100
commitc42f9f0a3eb540da2a46d2d4df4e575f0c3cdc4c (patch)
tree2b587cdd58eab0b4169ca900a6a7fdab0150dc24
parent10a85aea004484aae7e07f09235c75e90615787b (diff)
downloadrf-c42f9f0a3eb540da2a46d2d4df4e575f0c3cdc4c.tar.gz
change punctuation stripping
-rwxr-xr-xrf28
1 files changed, 18 insertions, 10 deletions
diff --git a/rf b/rf
index 338409d..c1de63a 100755
--- a/rf
+++ b/rf
@@ -6,7 +6,7 @@ use warnings;
# Default configuration
my %fmt;
-$fmt{r} = '%a (%y). {\fI%t\fR}. {\*Q%q\*U}. %n, %d. %c: %p. {Available: %w.}';
+$fmt{r} = '%a {(%y)}. {\fI%t\fR}. {\*Q%q\*U}. %n, %d. %c: %p. {Available: %w.}';
$fmt{f} = "\n(%A %y)";
$fmt{x} = "\n(%y)";
@@ -169,22 +169,30 @@ sub fmt {
my $val = $ref{lc $fld};
$val = join '; ', @$val if lc $fld eq 'a';
$val = fmtl($val) if $fld eq 'A';
- if ($val =~ /\.$/) {
- $fmt =~ s/\{([^{}%]*)%\Q$fld\E([^{}]*)}\.?/$1$val$2/g;
- $fmt =~ s/%\Q$fld\E\.?/$val/g;
+ if ($val =~ /[.,?!]$/) { # fix double punctuation
+ next if $fmt =~ s/\{([^{}%]*)%\Q$fld\E[.,?!]?([^{}]*)}/$1$val$2/g;
+ $fmt =~ s/%\Q$fld\E[.,?!]?/$val/g
} else {
- $fmt =~ s/\{([^{}%]*)%\Q$fld\E([^{}]*)}/$1$val$2/g;
- $fmt =~ s/%\Q$fld\E/$val/g;
+ next if $fmt =~ s/\{([^{}%]*)%\Q$fld\E([^{}]*)}/$1$val$2/g;
+ $fmt =~ s/%\Q$fld\E/$val/g
}
- } else {
+ } else { # remove escape syntax after failed interpolation
no warnings;
- $fmt =~ s/[.([]?\{([^{}%]*)%\Q$fld\E([^{}]*)}[.,?!:;\])]?//g;
- $fmt =~ s/[.([]?%\Q$fld\E[.,?!:;\])]?//g;
+ next if $fmt =~ s/\{([^{}%]*)%\Q$fld\E([^{}]*)}[.,?!:;]?//g;
+ $fmt =~ s/%\Q$fld\E[.,?!:;]?//g;
}
}
- $fmt =~ s/([^.]) +/$1 /g;
+
+ # strip superfluous spaces
$fmt =~ s/^ *//;
$fmt =~ s/ *$//;
+ $fmt =~ s/([^.]) +/$1 /g;
+ $fmt =~ s/([[(]) /$1/g;
+ $fmt =~ s/ ([\])])/$1/g;
+ $fmt =~ s/ ([.,])/$1/g;
+ # fix superfluous period after quote
+ $fmt =~ s/([.,?!]")\./$1/g;
+ $fmt =~ s/([.,?!]\\\*U)\./$1/g;
return $fmt;
}