diff options
author | John Ankarström <john@ankarstrom.se> | 2020-11-13 01:51:49 +0100 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2020-11-15 21:36:21 +0100 |
commit | 33c40ee8228a0ceac856a3962e9ad3af712625c5 (patch) | |
tree | 8f821d64bfbdab1ab0d86789f96a33ded240f707 | |
parent | 10a85aea004484aae7e07f09235c75e90615787b (diff) | |
download | rf-33c40ee8228a0ceac856a3962e9ad3af712625c5.tar.gz |
change punctuation stripping
It wasn't a good idea to strip parentheses, as a missing %y would cause
bugs like these:
(Author
when using the format (%A %y).
-rwxr-xr-x | rf | 28 | ||||
-rw-r--r-- | rf.1 | 2 |
2 files changed, 19 insertions, 11 deletions
@@ -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; } @@ -84,7 +84,7 @@ These macros control control the appearance of references and citations. .It Sy \&Fr Defines the format for references in the bibliography. .Pp -Default: %a (%y). {\\fI%t\\fR}. {\\*Q%q\\*U}. %n, %d. %c: %p. {Available: %w.} +Default: %a {(%y)}. {\\fI%t\\fR}. {\\*Q%q\\*U}. %n, %d. %c: %p. {Available: %w} .It Sy \&Ff Defines the format for .Dq full |