Skip to content

Commit

Permalink
tmesis.pl: escape non-7bit-ASCII bytes in output
Browse files Browse the repository at this point in the history
  • Loading branch information
roycewilliams committed Jul 23, 2023
1 parent 64ff806 commit df51bec
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/tmesis.pl
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,22 @@

for (my $word_pos = 0; $word_pos < $word_len; $word_pos++)
{
my $function_full = $function . $intpos_to_rulepos[$rule_pos + $word_pos] . $word_buf[$word_pos];
my $charspec = '';

push @rule, $function_full;
# If the byte is not 7-bit printable ASCII ...
if ($word_buf[$word_pos] =~ m/[\x00-\x19\x7f-\xff]/)
{
# ... escape it in rule syntax.
$charspec = '\x' . ord($word_buf[$word_pos]);
}
else
{
$charspec = $word_buf[$word_pos];
}

my $function_full = $function . $intpos_to_rulepos[$rule_pos + $word_pos] . $charspec;

$charspec && push @rule, $function_full;
}

print join (" ", @rule), "\n";
Expand Down

0 comments on commit df51bec

Please sign in to comment.