Skip to content
Permalink
Browse files

Add utf16le and utf16be encoding formats

* Add utf16le and utf16be to the encoding registry
* Allow calling .decode on a utf16 Buf and decoding as utf16be or
  utf16le
  • Loading branch information...
samcv committed Sep 17, 2018
1 parent 6c93fde commit e8a7564dc4e89a35d8cd15a943a2868567e5883d
Showing with 8 additions and 2 deletions.
  1. +2 −2 src/core/Buf.pm6
  2. +2 −0 src/core/Encoding/Registry.pm6
  3. +4 −0 src/core/Rakudo/Internals.pm6
@@ -491,8 +491,8 @@ my class utf16 does Blob[uint16] is repr('VMArray') {
multi method decode(utf16:D: $encoding = 'utf-16') {
my $enc = Rakudo::Internals.NORMALIZE_ENCODING($encoding);
die "Can not decode a utf-16 buffer as if it were $encoding"
unless $enc eq 'utf16';
nqp::p6box_s(nqp::decode(self, 'utf16'))
unless $enc eq 'utf16' || $enc eq 'utf16le' || $enc eq 'utf16be';
nqp::p6box_s(nqp::decode(self, $enc))
}
method encoding() { 'utf-16' }
multi method Str(utf16:D:) { self.decode }
@@ -13,6 +13,8 @@ my class Encoding::Registry {
nqp::list('utf8','utf-8'),
nqp::list('utf8-c8','utf8c8', 'utf-8-c8'),
nqp::list('utf16','utf-16'),
nqp::list('utf16le', 'utf-16le'),
nqp::list('utf16be', 'utf-16be'),
nqp::list('utf32','utf-32'),
nqp::list('ascii'),
nqp::list('iso-8859-1','iso_8859-1:1987','iso_8859-1','iso-ir-100',
@@ -277,6 +277,10 @@ my class Rakudo::Internals {
# utf16
'utf16', 'utf16',
'utf-16', 'utf16',
'utf16le', 'utf16le',
'utf-16le', 'utf16le',
'utf16be', 'utf16be',
'utf-16be', 'utf16be',
# utf32
'utf32', 'utf32',
'utf-32', 'utf32',

0 comments on commit e8a7564

Please sign in to comment.
You can’t perform that action at this time.