Skip to content

Commit 68a1a2f

Browse files
committed
Takes IO::String out of the big file refs Tux#24
1 parent 1efe200 commit 68a1a2f

File tree

6 files changed

+66
-59
lines changed

6 files changed

+66
-59
lines changed

META6.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"depends" : [ "Slang::Tuxic", "File::Temp" ],
99
"test-depends" : [ "Test", "Test::META" ],
1010
"provides" : {
11-
"Text::CSV" : "lib/Text/CSV.pm"
11+
"Text::CSV" : "lib/Text/CSV.pm",
12+
"IO::String" : "lib/IO/String.pm6"
1213
},
1314
"repo-type" : "git",
1415
"source-url" : "git://github.com/Tux/CSV.git",

lib/IO/String.pm6

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
use Slang::Tuxic; # Need it for space before parenthesis
2+
3+
unit class IO::String is IO::Handle;
4+
5+
has $.nl-in is rw;
6+
has $.nl-out is rw;
7+
has Bool $.ro is rw is default(False);
8+
has Str $!str;
9+
has Str @!content;
10+
11+
# my $fh = IO::String.new ($foo);
12+
multi method new (Str $str! is rw, *%init) {
13+
my \obj = self.new ($str.Str, |%init);
14+
obj.bind-str ($str);
15+
obj;
16+
}
17+
18+
# my $fh = IO::String.new ("foo");
19+
multi method new (Str $str!, *%init) {
20+
my \obj = self.bless;
21+
obj.nl-in = $*IN.nl-in;
22+
obj.nl-out = $*OUT.nl-out;
23+
obj.ro = %init<ro> if %init<ro>:exists;
24+
obj.nl-in = %init<nl-in> if %init<nl-in>:exists;
25+
obj.nl-out = %init<nl-out> if %init<nl-out>:exists;
26+
obj.print ($str);
27+
obj;
28+
}
29+
30+
method bind-str (Str $s is rw) {
31+
$!str := $s;
32+
}
33+
34+
method print (*@what) {
35+
if (my Str $str = @what.join ("")) {
36+
my Str @x = $str eq "" || !$.nl-in.defined
37+
?? $str
38+
!! |$str.split ($.nl-in, :v).map (-> $a, $b? --> Str { $a ~ ($b // "") });
39+
@x.elems > 1 && @x.tail eq "" and @x.pop;
40+
@!content.push: |@x;
41+
}
42+
self;
43+
}
44+
45+
method print-nl {
46+
self.print ($.nl-out);
47+
}
48+
49+
method get {
50+
@!content ?? @!content.shift !! Str;
51+
}
52+
53+
method close {
54+
$!str.defined && !$.ro and $!str = ~ self;
55+
}
56+
57+
method Str {
58+
@!content.join ("");
59+
}
60+

lib/Text/CSV.pm

+1-58
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use v6.c;
44
use Slang::Tuxic;
55
use File::Temp;
6+
use IO::String;
67

78
my $VERSION = "0.009";
89

@@ -99,65 +100,7 @@ sub progress (*@y) {
99100
$x.say;
100101
} # progress
101102

102-
# I don't want this inside Text::CSV
103-
class IO::String is IO::Handle {
104-
105-
has $.nl-in is rw;
106-
has $.nl-out is rw;
107-
has Bool $.ro is rw is default(False);
108-
has Str $!str;
109-
has Str @!content;
110-
111-
# my $fh = IO::String.new ($foo);
112-
multi method new (Str $str! is rw, *%init) {
113-
my \obj = self.new ($str.Str, |%init);
114-
obj.bind-str ($str);
115-
obj;
116-
}
117-
118-
# my $fh = IO::String.new ("foo");
119-
multi method new (Str $str!, *%init) {
120-
my \obj = self.bless;
121-
obj.nl-in = $*IN.nl-in;
122-
obj.nl-out = $*OUT.nl-out;
123-
obj.ro = %init<ro> if %init<ro>:exists;
124-
obj.nl-in = %init<nl-in> if %init<nl-in>:exists;
125-
obj.nl-out = %init<nl-out> if %init<nl-out>:exists;
126-
obj.print ($str);
127-
obj;
128-
}
129-
130-
method bind-str (Str $s is rw) {
131-
$!str := $s;
132-
}
133-
134-
method print (*@what) {
135-
if (my Str $str = @what.join ("")) {
136-
my Str @x = $str eq "" || !$.nl-in.defined
137-
?? $str
138-
!! |$str.split ($.nl-in, :v).map (-> $a, $b? --> Str { $a ~ ($b // "") });
139-
@x.elems > 1 && @x.tail eq "" and @x.pop;
140-
@!content.push: |@x;
141-
}
142-
self;
143-
}
144-
145-
method print-nl {
146-
self.print ($.nl-out);
147-
}
148-
149-
method get {
150-
@!content ?? @!content.shift !! Str;
151-
}
152-
153-
method close {
154-
$!str.defined && !$.ro and $!str = ~ self;
155-
}
156103

157-
method Str {
158-
@!content.join ("");
159-
}
160-
}
161104

162105
class RangeSet {
163106

t/32_getline.t

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use v6;
44
use Slang::Tuxic;
55

66
use Text::CSV;
7+
use IO::String;
78
use Test;
89

910
my $fh = IO::String.new (q:to/EOC/);

t/46_eol_si.t

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use Slang::Tuxic;
55

66
use Test;
77
use Text::CSV;
8+
use IO::String;
89

910
my Str $efn;
1011
my Str @rs = "\n", "\r\n", "\r";

t/77_getall.t

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use Slang::Tuxic;
55

66
use Test;
77
use Text::CSV;
8+
use IO::String;
89

910
my $csv = Text::CSV.new;
1011
my $tfn = "_77test.csv";

0 commit comments

Comments
 (0)