Skip to content

Commit

Permalink
Fix Encoding::Decoder so it works properly with a replacement
Browse files Browse the repository at this point in the history
Fix a write error to a read only variable and fix the signatures so it
doesn't fail when a Bool is passed in.
  • Loading branch information
samcv committed Mar 22, 2018
1 parent a3e4f9e commit 2760753
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions src/core/Encoding/Builtin.pm6
Expand Up @@ -16,9 +16,10 @@ class Encoding::Builtin does Encoding {

method alternative-names() { $!alternative-names }

method decoder(*%options --> Encoding::Decoder) {
%options<replacement> = self!rep-char(%options<replacement>) if %options<replacement>:exists && %options<replacement>.DEFINITE && %options<replacement> !=== False;
Encoding::Decoder::Builtin.new($!name, |%options)
method decoder(:$replacement, :$translate-nl, :$strict --> Encoding::Decoder) {
my $decoder = $replacement.DEFINITE && $replacement !=== False
?? Encoding::Decoder::Builtin.new($!name, :$strict, :$translate-nl, :replacement(self!rep-char($replacement)))
!! Encoding::Decoder::Builtin.new($!name, :$strict, :$translate-nl);
}

my int $is-win = Rakudo::Internals.IS-WIN;
Expand Down
4 changes: 2 additions & 2 deletions src/core/Encoding/Decoder/Builtin.pm6
@@ -1,9 +1,9 @@
my class Encoding::Decoder::Builtin is repr('Decoder') does Encoding::Decoder {
method new(str $encoding, :$translate-nl, Str :$replacement, Bool:D :$strict = False) {
method new(str $encoding, :$translate-nl, :$replacement, :$strict) {
nqp::decoderconfigure(nqp::create(self), $encoding,
nqp::hash(
'translate_newlines', $translate-nl ?? 1 !! 0,
'replacement', $replacement.defined ?? nqp::unbox_s($replacement) !! nqp::null(),
'replacement', $replacement.defined ?? nqp::unbox_s($replacement) !! nqp::null_s(),
'config', $strict ?? 0 !! 1
# Config set to 0 uses the decoder's new default, which is strict
# decoding. Setting to 1 uses the 6.c specced functionality where
Expand Down

0 comments on commit 2760753

Please sign in to comment.