-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Takes IO::String out of the big file refs Tux#24
- Loading branch information
Showing
6 changed files
with
66 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use Slang::Tuxic; # Need it for space before parenthesis | ||
|
||
unit class IO::String is IO::Handle; | ||
|
||
has $.nl-in is rw; | ||
has $.nl-out is rw; | ||
has Bool $.ro is rw is default(False); | ||
has Str $!str; | ||
has Str @!content; | ||
|
||
# my $fh = IO::String.new ($foo); | ||
multi method new (Str $str! is rw, *%init) { | ||
my \obj = self.new ($str.Str, |%init); | ||
obj.bind-str ($str); | ||
obj; | ||
} | ||
|
||
# my $fh = IO::String.new ("foo"); | ||
multi method new (Str $str!, *%init) { | ||
my \obj = self.bless; | ||
obj.nl-in = $*IN.nl-in; | ||
obj.nl-out = $*OUT.nl-out; | ||
obj.ro = %init<ro> if %init<ro>:exists; | ||
obj.nl-in = %init<nl-in> if %init<nl-in>:exists; | ||
obj.nl-out = %init<nl-out> if %init<nl-out>:exists; | ||
obj.print ($str); | ||
obj; | ||
} | ||
|
||
method bind-str (Str $s is rw) { | ||
$!str := $s; | ||
} | ||
|
||
method print (*@what) { | ||
if (my Str $str = @what.join ("")) { | ||
my Str @x = $str eq "" || !$.nl-in.defined | ||
?? $str | ||
!! |$str.split ($.nl-in, :v).map (-> $a, $b? --> Str { $a ~ ($b // "") }); | ||
@x.elems > 1 && @x.tail eq "" and @x.pop; | ||
@!content.push: |@x; | ||
} | ||
self; | ||
} | ||
|
||
method print-nl { | ||
self.print ($.nl-out); | ||
} | ||
|
||
method get { | ||
@!content ?? @!content.shift !! Str; | ||
} | ||
|
||
method close { | ||
$!str.defined && !$.ro and $!str = ~ self; | ||
} | ||
|
||
method Str { | ||
@!content.join (""); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters