Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
enable "UTF-8" as encoding name, as well as a few aliases for ISO-885…
…9-1; run encode.t
  • Loading branch information
moritz committed Nov 8, 2011
1 parent ac39fbb commit c0b2e3a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/Buf.pm
Expand Up @@ -54,7 +54,7 @@ class Buf does Positional {

method decode(Str:D $encoding = 'utf8') {
nqp::p6box_s $!buffer.get_string(
nqp::unbox_s $encoding.lc
nqp::unbox_s PARROT_ENCODING($encoding)
);
}
}
Expand Down
20 changes: 19 additions & 1 deletion src/core/Str.pm
Expand Up @@ -3,6 +3,24 @@ my class Range {... }
my class Match {... }
my class Buf {... }

sub PARROT_ENCODING(Str:D $s) {
my %map = (
'utf-8' => 'utf8',
# according to http://de.wikipedia.org/wiki/ISO-8859-1
'iso_8859-1:1987' => 'iso-8859-1',
'iso_8859-1' => 'iso-8859-1',
'iso-ir-100' => 'iso-8859-1',
'latin1' => 'iso-8859-1',
'latin-1' => 'iso-8859-1',
'csisolatin1' => 'iso-8859-1',
'l1' => 'iso-8859-1',
'ibm819' => 'iso-8859-1',
'cp819' => 'iso-8859-1',
);
my Str $lc = lc($s);
%map{$lc} // $lc;
}

my class Str does Stringy {
submethod BUILD(:$value as Str = '') {
nqp::bindattr_s(self, Str, '$!value', nqp::unbox_s($value))
Expand Down Expand Up @@ -467,7 +485,7 @@ my class Str does Stringy {
pir::set__vPs(nqp::getattr($buf, Buf, '$!buffer'),
pir::trans_encoding__ssi(
nqp::unbox_s(self),
pir::find_encoding__is(nqp::unbox_s(nqp::p6decont($encoding.lc)))
pir::find_encoding__is(nqp::unbox_s(PARROT_ENCODING($encoding)))
)
);
$buf;
Expand Down
2 changes: 1 addition & 1 deletion t/spectest.data
Expand Up @@ -551,7 +551,7 @@ S32-str/capitalize.t # icu
S32-str/chomp.t
S32-str/chop.t
S32-str/comb.t # icu
# S32-str/encode.t # err: encoding 'utf-8' not found
S32-str/encode.t
S32-str/flip.t
# S32-str/indent.t # err: Method 'indent' not found for invocant of class 'Str'
S32-str/index.t
Expand Down

0 comments on commit c0b2e3a

Please sign in to comment.