Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add :enc/:encoding support to &open
  • Loading branch information
moritz committed Jun 27, 2012
1 parent 5e3dfe9 commit 88a9d69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/ChangeLog
Expand Up @@ -2,6 +2,7 @@ New in 2012.07
+ Deprecated SAFE.setting in favor of RESTRICTED.setting
+ Ranges can now interpolate in argument lists
+ The built-in meta-objects (such as Metamodel::ClassHOW) now inherit from Any
+ &open now supports :enc/:encoding

New in 2012.06
+ Rakudo is now compiled with the same regex engine as user-space regexes use
Expand Down
9 changes: 5 additions & 4 deletions src/core/IO.pm
Expand Up @@ -34,7 +34,8 @@ class IO {
has $.path;

proto method open(|$) { * }
multi method open($path, :$r, :$w, :$a, :$bin, :$chomp = Bool::True) {
multi method open($path, :$r, :$w, :$a, :$bin, :$chomp = Bool::True,
:enc(:$encoding) = 'utf8') {
my $mode = $w ?? 'w' !! ($a ?? 'wa' !! 'r');
# TODO: catch error, and fail()
nqp::bindattr(self, IO, '$!PIO',
Expand All @@ -44,7 +45,7 @@ class IO {
);
$!path = $path;
$!chomp = $chomp;
$!PIO.encoding($bin ?? 'binary' !! 'utf8');
$!PIO.encoding($bin ?? 'binary' !! PARROT_ENCODING($encoding));
self;
}

Expand Down Expand Up @@ -260,8 +261,8 @@ sub rmdir($path) {
}

proto sub open(|$) { * }
multi sub open($path, :$r, :$w, :$a, :$bin, :$chomp = Bool::True) {
IO.new.open($path, :$r, :$w, :$a, :$bin, :$chomp);
multi sub open($path, :$r, :$w, :$a, :$bin, :$chomp = Bool::True, :enc(:$encoding) = 'utf8') {
IO.new.open($path, :$r, :$w, :$a, :$bin, :$chomp, :$encoding);
}

proto sub lines(|$) { * }
Expand Down

0 comments on commit 88a9d69

Please sign in to comment.