Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

enable "UTF-8" as encoding name, as well as a few aliases for ISO-885…

…9-1; run encode.t
  • Loading branch information...
commit c0b2e3a205c7051ad8dfeb4da90e236c9ac3f029 1 parent ac39fbb
@moritz moritz authored
Showing with 21 additions and 3 deletions.
  1. +1 −1  src/core/Buf.pm
  2. +19 −1 src/core/Str.pm
  3. +1 −1  t/spectest.data
View
2  src/core/Buf.pm
@@ -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)
);
}
}
View
20 src/core/Str.pm
@@ -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))
@@ -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;
View
2  t/spectest.data
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.