Skip to content

Commit

Permalink
Add utf16le and utf16be encoding formats
Browse files Browse the repository at this point in the history
* 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 e8a7564
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/Buf.pm6
Expand Up @@ -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 }
Expand Down
2 changes: 2 additions & 0 deletions src/core/Encoding/Registry.pm6
Expand Up @@ -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',
Expand Down
4 changes: 4 additions & 0 deletions src/core/Rakudo/Internals.pm6
Expand Up @@ -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',
Expand Down

0 comments on commit e8a7564

Please sign in to comment.