Skip to content

Commit

Permalink
Make sure IO::Handle.encoding passes replacement, strict to decoder
Browse files Browse the repository at this point in the history
The signature had :$replacement and :$strict but they were not passed
through to Encoding.decoder, though they worked fine with the encoder.

In addition add a :$translate-nl argument to allow changing the value.
Previously the default of $translate-nl = True was passed into the
decoder and encoder's but there was no way to configure it.
  • Loading branch information
samcv committed Mar 22, 2018
1 parent 2760753 commit 37fc288
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/core/IO/Handle.pm6
Expand Up @@ -730,7 +730,7 @@ my class IO::Handle {

proto method encoding(|) {*}
multi method encoding(IO::Handle:D:) { $!encoding // Nil }
multi method encoding(IO::Handle:D: $new-encoding is copy, :$replacement, :$strict) {
multi method encoding(IO::Handle:D: $new-encoding is copy, :$replacement, :$strict, Bool:D :$translate-nl = True) {
with $new-encoding {
if $_ eq 'bin' {
$_ = Nil;
Expand All @@ -747,11 +747,11 @@ my class IO::Handle {
with $new-encoding {
my $prev-decoder := $!decoder;
my $encoding = Encoding::Registry.find($new-encoding);
$!decoder := $encoding.decoder(:translate-nl);
$!decoder := $encoding.decoder(:$translate-nl, :$replacement, :$strict);
$!decoder.set-line-separators($!nl-in.list);
$!decoder.add-bytes($prev-decoder.consume-exactly-bytes($available))
if $available;
$!encoder := $encoding.encoder(:translate-nl, :$replacement, :$strict);
$!encoder := $encoding.encoder(:$translate-nl, :$replacement, :$strict);
$!encoding = $encoding.name;
}
else {
Expand All @@ -766,9 +766,9 @@ my class IO::Handle {
# No previous decoder; make a new one if needed, otherwise no change.
with $new-encoding {
my $encoding = Encoding::Registry.find($new-encoding);
$!decoder := $encoding.decoder(:translate-nl);
$!decoder := $encoding.decoder(:$translate-nl, :$replacement, :$strict);
$!decoder.set-line-separators($!nl-in.list);
$!encoder := $encoding.encoder(:translate-nl, :$replacement, :$strict);
$!encoder := $encoding.encoder(:$translate-nl, :$replacement, :$strict);
$!encoding = $encoding.name;
}
else {
Expand Down

0 comments on commit 37fc288

Please sign in to comment.