-
-
Notifications
You must be signed in to change notification settings - Fork 372
/
Builtin.pm6
37 lines (33 loc) · 1.08 KB
/
Builtin.pm6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
my class Encoding::Encoder::Builtin does Encoding::Encoder {
has str $!encoding;
has Blob $!type;
has $!replacement;
has int $!config;
method new(Str $encoding, Blob:U $type, :$replacement, :$strict) {
nqp::create(self)!setup($encoding, $type, :$replacement, :$strict)
}
method !setup($encoding, $type, :$replacement, :$strict) {
$!encoding = $encoding;
$!type := nqp::can($type.HOW, 'pun') ?? $type.^pun !! $type.WHAT;
$!replacement = $replacement.defined ?? $replacement !! nqp::null_s();
$!config = $strict ?? 0 !! 1;
#?if jvm
X::NYI.new(feature => 'encoding with replacement').throw if $replacement.defined;
X::NYI.new(feature => 'encoding with strict').throw if $strict;
#?endif
self
}
method encode-chars(str $str --> Blob:D) {
#?if !jvm
nqp::encoderepconf($str,
$!encoding,
$!replacement,
nqp::create($!type),
$!config)
#?endif
#?if jvm
nqp::encode($str, $!encoding, nqp::create($!type));
#?endif
}
}
# vim: ft=perl6 expandtab sw=4