commit 6990df581565ad3aba6d1a73578ae10c210f805d
parent b174c1557b4acae8b3f30c0469d7b8f26c27bb8b
Author: lumidify <nobody@lumidify.org>
Date: Fri, 17 Apr 2020 10:00:39 +0200
Small cleanup
Diffstat:
1 file changed, 11 insertions(+), 17 deletions(-)
diff --git a/transliterate.pl b/transliterate.pl
@@ -1093,7 +1093,7 @@ sub push_unknown {
# specifies if the match is only valid when $config->{"beforeword"}
# or $config->{"afterword"} occur before or after it, respectively
sub replace_match {
- my ($config, $args, $replace_config, $substrings, $debug_msg) = @_;
+ my ($config, $replace_config, $substrings, $debug_msg) = @_;
my $beginword = exists $replace_config->{"options"}->{"beginword"};
my $endword = exists $replace_config->{"options"}->{"endword"};
my $fullword = $beginword && $endword;
@@ -1131,9 +1131,7 @@ sub replace_match {
my $i1 = 0;
while ($substrings->[$i]->[1] =~ m/$word/g) {
if (!$found_word) {
- if ($args->{"debug"}) {
- print $debug_msg;
- }
+ print $debug_msg if $debug_msg;
$found_word = 1;
if ($i != 0) {
push(@substrings_new, @{$substrings}[0..$i-1]);
@@ -1163,14 +1161,10 @@ sub replace_match {
my $orig_str = substr($substrings->[$i]->[1], $i0, $i1-$i0);
my $replace_str = $replace_word // $orig_str;
if ($replace_config->{"options"}->{"nofinal"}) {
- if ($args->{"debug"}) {
- warn "Replaced (nofinal) \"$orig_str\" with \"$replace_str\"\n";
- }
+ warn "Replaced (nofinal) \"$orig_str\" with \"$replace_str\"\n" if $debug_msg;
push_unknown \@substrings_new, $orig_str, $replace_str;
} else {
- if ($args->{"debug"}) {
- warn "Replaced \"$orig_str\" with \"$replace_str\"\n";
- }
+ warn "Replaced \"$orig_str\" with \"$replace_str\"\n" if $debug_msg;
push(@substrings_new, [1, $replace_str, $orig_str]);
}
$last_idx = $i1;
@@ -1190,9 +1184,9 @@ sub replace_match {
# $replace_config->{"beginword"}, $replace_config->{"endword"} -
# same as in `replace_match`
sub replace_group {
- my ($config, $args, $replace_config, $substrings, $debug_msg) = @_;
+ my ($config, $replace_config, $substrings, $debug_msg) = @_;
my @substrings_new;
- my $anything_replaced = 0;
+ my $word_found = 0;
# Recurse backwords towards the root node of the trie to find the first
# node with a key "final" which satisfies the ending condition (if "endword" is set)
# Returns the id *after* the last match and the node that was found
@@ -1248,10 +1242,10 @@ sub replace_group {
} else {
my $orig = substr($s->[1], $start_i, $i-$start_i);
my $final = $tmp_cur_node->{"final"};
- if ($args->{"debug"}) {
- if (!$anything_replaced) {
+ if ($debug_msg) {
+ if (!$word_found) {
warn $debug_msg;
- $anything_replaced = 1;
+ $word_found = 1;
}
warn "Replaced \"$orig\" with \"$final\"\n";
}
@@ -1299,7 +1293,7 @@ sub replace_line {
$debug_msg .= " (ignore)\n";
}
}
- replace_match($config, $args, $replacement, $substrings, $debug_msg);
+ replace_match($config, $replacement, $substrings, $debug_msg);
} elsif ($replacement->{"type"} eq "group") {
my $debug_msg;
if ($args->{"debug"}) {
@@ -1307,7 +1301,7 @@ sub replace_line {
my $tables = '"' . join('" "', @{$replacement->{"tables"}}) . '"';
$debug_msg = "Group ($options): $tables\n";
}
- replace_group($config, $args, $replacement, $substrings, $debug_msg);
+ replace_group($config, $replacement, $substrings, $debug_msg);
}
}
# splits all words at the end so that the splitting characters