Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 494 lines (429 sloc) 14.524 kB
440b679 @moritz move Any-str methods to Cool
moritz authored
1 augment class Cool {
5ec16a7 @jnthn Get several more cases of smart-matching to work again.
jnthn authored
2
1d7ec80 @jnthn Add some of Any-str.pm back in.
jnthn authored
3 our Int multi method bytes() is export {
4 pir::box__PI(pir::bytelength__IS(self))
5 }
6
b9b14f9 @colomon Slightly awkward but functional implementation of capitalize.
colomon authored
7 # The spec has a more elegant approach for this,
8 # but this one works now.
9 our Str multi method capitalize() {
10 self.lc.split(/\w+/, :all).map({ .Str.ucfirst }).join('');
11 }
12
33bd05e @colomon Add chars and substr.
colomon authored
13 our Int multi method chars() is export {
14 pir::length__IS(self);
15 }
16
cb8ea77 @colomon Add Any.chomp.
colomon authored
17 our multi method chomp() is export {
d1015f0 @pmichaud Rewrite .chomp method to be more efficient. With this change, the ti…
pmichaud authored
18 # in PIR for speed
19 Q:PIR {
20 $P0 = find_lex 'self'
21 $S0 = $P0
22 unless $S0 > '' goto done
23 $I0 = ord $S0, -1
24 unless $I0 == 10 goto done
25 $S0 = chopn $S0, 1
26 unless $S0 > '' goto done
27 $I0 = ord $S0, -1
28 unless $I0 == 13 goto done
29 $S0 = chopn $S0, 1
30 done:
2ac5feb @colomon Have Cool.chomp return a proper Str.
colomon authored
31 %r = new ['Str']
32 assign %r, $S0
cb8ea77 @colomon Add Any.chomp.
colomon authored
33 }
34 }
35
668719b @moritz implement Cool.samecase, .subst(:samespace) and ss///
moritz authored
36 multi method subst($matcher, $replacement,
37 :ii(:$samecase), :ss(:$samespace), *%options) {
0aed40a @moritz rewrite .subst in terms of .match
moritz authored
38 my @matches = self.match($matcher, |%options);
39 return self unless @matches;
40 return self if @matches == 1 && !@matches[0];
41 my $prev = 0;
42 my $result = '';
43 for @matches -> $m {
44 $result ~= self.substr($prev, $m.from - $prev);
4e3d29d @qiuhw add :samecase to Cool.subst
qiuhw authored
45
668719b @moritz implement Cool.samecase, .subst(:samespace) and ss///
moritz authored
46 my $real_replacement = ~($replacement ~~ Callable ?? $replacement($m) !! $replacement);
47 $real_replacement = $real_replacement.samecase(~$m) if $samecase;
48 $real_replacement = $real_replacement.samespace(~$m) if $samespace;
4e3d29d @qiuhw add :samecase to Cool.subst
qiuhw authored
49 $result ~= $real_replacement;
0aed40a @moritz rewrite .subst in terms of .match
moritz authored
50 $prev = $m.to;
16efb68 @moritz implement Str.subst($matcher, Code, :g)
moritz authored
51 }
0aed40a @moritz rewrite .subst in terms of .match
moritz authored
52 my $last = @matches.pop;
53 $result ~= self.substr($last.to);
54 $result;
16efb68 @moritz implement Str.subst($matcher, Code, :g)
moritz authored
55 }
56
36e2631 @colomon Set appropriate default value for Any.comb's Regex argument.
colomon authored
57 multi method comb(Regex $matcher = /./, $limit = *, :$match) {
3a14795 @moritz initial implementation of .comb in Any-str (lacks limit)
moritz authored
58 my $c = 0;
b155b40 @moritz remove ugly workaround as suggested by jnthn++
moritz authored
59 my $l = $limit ~~ ::Whatever ?? Inf !! $limit;
bd7d2fb @moritz implement limit in .comb
moritz authored
60 gather while $l > 0 && (my $m = self.match($matcher, :c($c))) {
ed321b4 @colomon Fix comb version of the match with take bug fixed earlier today in sp…
colomon authored
61 if $match {
62 my $m-clone = $m;
63 take $m-clone;
64 } else {
65 take ~$m;
66 }
3a14795 @moritz initial implementation of .comb in Any-str (lacks limit)
moritz authored
67 $c = $m.to == $c ?? $c + 1 !! $m.to;
bd7d2fb @moritz implement limit in .comb
moritz authored
68 --$l;
3a14795 @moritz initial implementation of .comb in Any-str (lacks limit)
moritz authored
69 }
70 }
71
43f00da @moritz type-constraint samecase() pattern to Cool
moritz authored
72 multi method samecase(Cool $pattern) is export {
73e8d42 @moritz implement samecase()
moritz authored
73 my $result = '';
74 my $p = '';
75 my @pattern = $pattern.comb;
76 for self.comb -> $s {
77 $p = @pattern.shift if @pattern;
78 if $p ~~ /<.upper>/ {
79 $result ~= $s.uc;
80 } elsif $p ~~ /<.lower>/ {
81 $result ~= $s.lc;
82 } else {
83 $result ~= $s;
84 }
85 }
86 $result;
87 }
88
668719b @moritz implement Cool.samecase, .subst(:samespace) and ss///
moritz authored
89 method samespace($other as Str) {
90 my @pieces = self.split(/\s+/);
91 my @new_spaces = $other.comb(/\s+/, @pieces-1);
92
93 my @new = @pieces[0..^@new_spaces] Z @new_spaces;
94
95 if @new_spaces < @pieces-1 {
96 my $remainder = self ~~ m:nth(@pieces-1)/\s+/;
97 @new.push(self.substr($remainder.from-1));
98 }
99 else {
100 @new.push(@pieces[*-1]);
101 }
102
103 return @new.join;
104 }
105
106
6c33726 @moritz Implement Any.split(Regex).
moritz authored
107 multi method split(Regex $matcher, $limit = *, :$all) {
108 my $c = 0;
b155b40 @moritz remove ugly workaround as suggested by jnthn++
moritz authored
109 my $l = $limit ~~ ::Whatever ?? Inf !! $limit - 1;
8aff115 @moritz fix split() with zero-width matches; also run two more test files
moritz authored
110 my $prev-pos = 0;
111 return if $l < 0;
112 return self.list if $l == 0;
113 gather {
114 for @.match($matcher, :x(1..$l)) -> $m {
115 take self.substr($prev-pos, $m.from - $prev-pos);
116 take $m if $all;
117 $prev-pos = $m.to;
6c33726 @moritz Implement Any.split(Regex).
moritz authored
118 }
8aff115 @moritz fix split() with zero-width matches; also run two more test files
moritz authored
119 take self.substr($prev-pos);
500e7f8 @colomon Clone Split on Regex to get Split on Str.
colomon authored
120 }
121 }
122
3fba2c3 @moritz implement :x in Str.subst; implement :all in Str.split(Str)
moritz authored
123 multi method split($delimiter, $limit = *, :$all) {
124 my $match-string = $delimiter.Str;
8aff115 @moritz fix split() with zero-width matches; also run two more test files
moritz authored
125 return if self eq '' && $delimiter eq '';
500e7f8 @colomon Clone Split on Regex to get Split on Str.
colomon authored
126 my $c = 0;
127 my $l = $limit ~~ ::Whatever ?? Inf !! $limit - 1;
a7929a5 @colomon Get limit argument working on the split functions.
colomon authored
128 if $l >= 0 {
129 gather {
18e04b9 @colomon Rewrite the core of Any.split(Str) to handle the split("") case.
colomon authored
130 while $l-- > 0 {
4b83f16 @colomon Change Any.split(Str) to be Any.split(Any).
colomon authored
131 if ($match-string eq "") {
18e04b9 @colomon Rewrite the core of Any.split(Str) to handle the split("") case.
colomon authored
132 last unless $c + 1 < self.chars;
133 take self.substr($c, 1);
134 $c++;
135 } else {
4b83f16 @colomon Change Any.split(Str) to be Any.split(Any).
colomon authored
136 my $m = self.index($match-string, $c);
2df6282 @colomon Any.index now returns Mu if it doesn't find the string. Any.split(An…
colomon authored
137 last if $m.notdef; # CHEAT, but the best I can do for now
18e04b9 @colomon Rewrite the core of Any.split(Str) to handle the split("") case.
colomon authored
138 take self.substr($c, $m - $c);
3fba2c3 @moritz implement :x in Str.subst; implement :all in Str.split(Str)
moritz authored
139 take $match-string if $all;
2df6282 @colomon Any.index now returns Mu if it doesn't find the string. Any.split(An…
colomon authored
140 $c = $m + $match-string.chars;
18e04b9 @colomon Rewrite the core of Any.split(Str) to handle the split("") case.
colomon authored
141 }
a7929a5 @colomon Get limit argument working on the split functions.
colomon authored
142 }
143 take self.substr($c);
500e7f8 @colomon Clone Split on Regex to get Split on Str.
colomon authored
144 }
a7929a5 @colomon Get limit argument working on the split functions.
colomon authored
145 } else {
146 Nil;
6c33726 @moritz Implement Any.split(Regex).
moritz authored
147 }
148 }
149
48d581f @colomon Change $given_len to $length to match the spec.
colomon authored
150 our Str multi method substr($start, $length?) is export {
151 my $len = $length // self.chars;
33bd05e @colomon Add chars and substr.
colomon authored
152 if ($len < 0) {
153 if ($start >= 0) {
154 $len += self.chars;
155 }
156 $len -= $start;
157 }
158
8df8ad7 @colomon Try to handle the .substr cases where $start is outside the length of…
colomon authored
159 if ($start > self.chars || $start < -self.chars) {
160 return Mu;
161 }
162
4bf6c0f @moritz return Perl 6 strings from substr and join. Patch courtesy of felliott++
moritz authored
163 ~pir::substr(self, $start, $len);
33bd05e @colomon Add chars and substr.
colomon authored
164 }
165
3a6b43f @moritz First shot at pure-Perl Cool.trans
moritz authored
166 multi method trans(*@changes) {
167 my sub expand($s) {
168 return $s.list if $s ~~ Iterable|Positional;
169 gather for $s.comb(/ (\w) '..' (\w) | . /, :match) {
170 if .[0] {
171 take $_ for ~.[0] .. ~.[1];
172 } else {
173 take ~$_;
174 }
175 }
176 }
177
178 my %c;
179 my %prefixes;
180 for (@changes) -> $p {
181 die "$p.perl is not a Pair" unless $p ~~ Pair;
182 my @from = expand $p.key;
183 my @to = expand $p.value;
184 # warn "Substitution is longer than pattern\n" if @to > @from;
185 if @to {
186 @to = @to xx ceiling(@from / @to);
187 } else {
188 @to = '' xx @from;
189 }
190 for @from Z @to -> $f, $t {
191 if %c.exists($f) && %c{$f} ne $t {
0b83903 @Util Fixed various typos in comments and error messages.
Util authored
192 # warn "Ambiguous transliteration rule for '$f'; "
3a6b43f @moritz First shot at pure-Perl Cool.trans
moritz authored
193 # ~ "using the first one (transliteration to '$t')";
194 } else {
195 if $f.chars > 1 {
196 %prefixes{$f.substr(0, 1)} //= [];
197 %prefixes{$f.substr(0, 1)}.push($f);
198 }
199 %c{$f} = $t;
200 }
201 }
202 }
203
204 # should be replaced by a proper trie implementation
205 # at some point
206 for %prefixes.keys {
207 %prefixes{$_}.=sort({-.chars});
208 }
209
210 my @res;
211 my $l = $.chars;
212 loop (my $i = 0; $i < $l; ++$i) {
213 my $c = $.substr($i, 1);
214 my $success = 0;
215 if %prefixes.exists($c) {
216 for %prefixes{$c}.list {
217 if self.substr($i, .chars) eq $_ {
218 @res.push: %c{$_};
219 $success = 1;
220 $i += .chars - 1;
221 last;
222 }
223 }
224 }
225 unless $success {
226 @res.push: %c.exists($c)
227 ?? %c{$c}
228 !! $c;
229 }
230 }
231 @res.join: '';
232 }
233
234
6373928 @tene Tweak Str.index to be slightly more-correct, also fixing Str.split(Str)
tene authored
235 # S32/Str says that this should always return a StrPos object
2df60cd @colomon Port of index from PIR into (mostly) p6.
colomon authored
236 our Int multi method index($substring, $pos = 0) is export {
237 if ($substring.chars == 0) {
238 my $string_length = self.chars;
239 return $pos < $string_length ?? $pos !! $string_length;
240 }
241
242 my $result = pir::index__ISSi(self, $substring, $pos);
920640f @colomon Replace several cheat returns of Mu with actual returns of fail messa…
colomon authored
243 fail("Substring '$substring' not found in '{self}'") if $result < 0;
2df60cd @colomon Port of index from PIR into (mostly) p6.
colomon authored
244 return $result;
245
246 # also used to be a the following error message, but the condition
247 # was never checked:
248 # .tailcall '!FAIL'("Attempt to index from negative position")
249 }
250
cccc121 @moritz re-enable Cool.rindex
moritz authored
251
ff4ced6 @colomon Initial stabs at Any.trim and Any.rindex. Neither works, and rindex …
colomon authored
252 # S32/Str says that this should always return a StrPos object
cccc121 @moritz re-enable Cool.rindex
moritz authored
253 our Int multi method rindex($substring, $pos?) is export {
254 if ($substring.chars == 0) {
255 my $string_length = self.chars;
256 return $pos.defined && $pos < $string_length ?? $pos !! $string_length;
257 }
258
259 my $result = (~self).reverse_index($substring, $pos);
260 fail("Substring '$substring' not found in '{self}'") if $result < 0;
261 return $result;
262 }
ff4ced6 @colomon Initial stabs at Any.trim and Any.rindex. Neither works, and rindex …
colomon authored
263
1d7ec80 @jnthn Add some of Any-str.pm back in.
jnthn authored
264 our Str multi method chop() is export {
265 self.substr(0, -1)
266 }
267
268 our Str multi method fmt(Str $format = '%s') {
269 sprintf($format, self)
270 }
271
4fc3af7 @colomon Add protos for uc, lc, ucfirst, and lcfirst.
colomon authored
272 our Str multi method lc() {
1d7ec80 @jnthn Add some of Any-str.pm back in.
jnthn authored
273 ~(pir::downcase__SS(self))
274 }
275
4fc3af7 @colomon Add protos for uc, lc, ucfirst, and lcfirst.
colomon authored
276 our Str multi method lcfirst() {
1d7ec80 @jnthn Add some of Any-str.pm back in.
jnthn authored
277 self gt '' ?? self.substr(0,1).lc ~ self.substr(1) !! ""
278 }
279
c515f5f @colomon Implement :overlap for Any.match.
colomon authored
280 our multi method match(Regex $pat,
281 :c(:$continue),
282 :g(:$global),
283 :pos(:$p),
cf5afac @moritz implement :x in Any.match; also test it
moritz authored
284 :$x,
96a0ffe @moritz allow all the adverbs on s/// that Cool.subst understands
moritz authored
285 :st(:nd(:rd(:th(:$nth)))),
c515f5f @colomon Implement :overlap for Any.match.
colomon authored
286 :ov(:$overlap)) {
816a4fc @colomon Better support for :c / :continue in match, and turn on S05-modifier/…
colomon authored
287 if $continue ~~ Bool {
288 note ":c / :continue requires a position in the string";
289 fail ":c / :continue requires a position in the string";
290 }
2d0fc2b @moritz implement :p/:pos in Regex.match
moritz authored
291 my %opts;
292 %opts<p> = $p if defined $p;
293 %opts<c> = $continue // 0 unless defined $p;
72ed16f @moritz simplify .match(:x) implementation a wee bit
moritz authored
294 my $x_upper = -1;
cf5afac @moritz implement :x in Any.match; also test it
moritz authored
295 if defined($x) {
0aed40a @moritz rewrite .subst in terms of .match
moritz authored
296 return if $x == 0;
cf5afac @moritz implement :x in Any.match; also test it
moritz authored
297 if $x ~~ Range {
298 $x_upper = $x.excludes_max ?? $x.max - 1 !! $x.max;
299 } else {
300 $x_upper = $x;
301 }
302 }
2d0fc2b @moritz implement :p/:pos in Regex.match
moritz authored
303
cf5afac @moritz implement :x in Any.match; also test it
moritz authored
304 if $global || $nth.defined || $overlap || ($x.defined && $x_upper > 1) {
4d58dd1 @colomon Make match's :nth parameter work with the new lists.
colomon authored
305 my $nth-list = $nth.defined ?? $nth.flat !! $nth;
475d1c7 @colomon Change .match to support the new list approach for :nth.
colomon authored
306 my $next-index;
4d58dd1 @colomon Make match's :nth parameter work with the new lists.
colomon authored
307 if $nth-list.defined {
308 return if !$nth-list;
309 $next-index = $nth-list.shift;
310 return if +$next-index < 1;
475d1c7 @colomon Change .match to support the new list approach for :nth.
colomon authored
311 }
312
cf5afac @moritz implement :x in Any.match; also test it
moritz authored
313 my $taken = 0;
31598e9 @colomon Add beginnings of support for :nth argument to .match.
colomon authored
314 my $i = 1;
250adbb @pmichaud Initial fixes towards enabling Rakudo-specific Match objects.
pmichaud authored
315 my @r = gather while my $m = Cursor.parse(self, :rule($pat), |%opts) {
ec37acc @colomon In .match's global path, copy the match variable, then call "take" wi…
colomon authored
316 my $m-copy = $m;
4d58dd1 @colomon Make match's :nth parameter work with the new lists.
colomon authored
317 if !$nth-list.defined || $i == $next-index {
31598e9 @colomon Add beginnings of support for :nth argument to .match.
colomon authored
318 take $m-copy;
cf5afac @moritz implement :x in Any.match; also test it
moritz authored
319 $taken++;
475d1c7 @colomon Change .match to support the new list approach for :nth.
colomon authored
320
4d58dd1 @colomon Make match's :nth parameter work with the new lists.
colomon authored
321 if ($nth-list.defined) {
322 while ?$nth-list && $next-index <= $i {
323 $next-index = $nth-list.shift;
475d1c7 @colomon Change .match to support the new list approach for :nth.
colomon authored
324 }
4d58dd1 @colomon Make match's :nth parameter work with the new lists.
colomon authored
325 last if $next-index <= $i;
475d1c7 @colomon Change .match to support the new list approach for :nth.
colomon authored
326 }
31598e9 @colomon Add beginnings of support for :nth argument to .match.
colomon authored
327 }
72ed16f @moritz simplify .match(:x) implementation a wee bit
moritz authored
328 last if $taken == $x_upper;
c515f5f @colomon Implement :overlap for Any.match.
colomon authored
329
330 if ($overlap) {
331 %opts<c> = $m.from + 1;
52d140e @moritz implement :g in .match
moritz authored
332 } else {
c515f5f @colomon Implement :overlap for Any.match.
colomon authored
333 if $m.to == $m.from {
334 %opts<c> = $m.to + 1;
9d7428f @moritz fix interaction between :g and :p regex modifiers in Cool.match
moritz authored
335 if $p.defined {
336 warn "multiple matches with :p terminated by zero-width match\n";
337 last;
338 }
c515f5f @colomon Implement :overlap for Any.match.
colomon authored
339 } else {
340 %opts<c> = $m.to;
9d7428f @moritz fix interaction between :g and :p regex modifiers in Cool.match
moritz authored
341 %opts<p> = $m.to if $p.defined;
c515f5f @colomon Implement :overlap for Any.match.
colomon authored
342 }
52d140e @moritz implement :g in .match
moritz authored
343 }
c515f5f @colomon Implement :overlap for Any.match.
colomon authored
344
31598e9 @colomon Add beginnings of support for :nth argument to .match.
colomon authored
345 $i++;
52d140e @moritz implement :g in .match
moritz authored
346 }
cf5afac @moritz implement :x in Any.match; also test it
moritz authored
347 if $x.defined && $taken !~~ $x {
348 return;
349 }
350 return |@r;
52d140e @moritz implement :g in .match
moritz authored
351 } else {
250adbb @pmichaud Initial fixes towards enabling Rakudo-specific Match objects.
pmichaud authored
352 Cursor.parse(self, :rule($pat), |%opts);
52d140e @moritz implement :g in .match
moritz authored
353 }
cbeb219 @pmichaud Add initial version of regex matches.
pmichaud authored
354 }
25cff28 @moritz also accept non-Regex objects as pattern in Any.match
moritz authored
355 multi method match($pat, *%options) {
356 self.match(rx{ $pat }, |%options);
357 }
cbeb219 @pmichaud Add initial version of regex matches.
pmichaud authored
358
6f25191 @colomon Allow ord to handle a string with more than one character (in list co…
colomon authored
359 our multi method ord() {
360 given self.chars {
361 when 0 { fail('Can not take ord of empty string'); }
362 when 1 { pir::box__PI(pir::ord__IS(self)); }
363 default {
364 gather for self.comb {
365 take pir::box__PI(pir::ord__IS($_))
366 }
367 }
368 }
1d7ec80 @jnthn Add some of Any-str.pm back in.
jnthn authored
369 }
370
371 # TODO: Return type should be a Char once that is supported.
372 our Str multi method p5chop() is export {
373 my $char = '';
374
375 for @.list -> $str is rw {
376 if $str gt '' {
377 $char = $str.substr($str.chars - 1, 1);
378 $str = $str.chop;
379 }
380 }
381
382 $char
383 }
384
9d5018c @colomon Add Any.eval with obvious definition.
colomon authored
385 multi method eval() {
386 eval(~self);
387 }
388
1d7ec80 @jnthn Add some of Any-str.pm back in.
jnthn authored
389 multi method flip() is export {
79f754a @moritz use parrot's String.reverse for Str.flip
moritz authored
390 ~ Q:PIR {
391 $P0 = box ''
392 $P1 = find_lex 'self'
393 $S0 = $P0.'reverse'($P1)
394 %r = box $S0
395 }
1d7ec80 @jnthn Add some of Any-str.pm back in.
jnthn authored
396 }
397
8564837 @colomon Add trim-leading and trim-trailing, and reimplement trim in terms of …
colomon authored
398 # Not yet spec'd, I expect it will be renamed
399 multi method trim-leading() is export {
ad2afb5 @moritz stringify self in Cool.trim-{leading,trailing}
moritz authored
400 if ~self ~~ /^\s*:(.*)$/ {
8564837 @colomon Add trim-leading and trim-trailing, and reimplement trim in terms of …
colomon authored
401 ~$/[0];
402 } else {
403 self;
404 }
405 }
406
407 # Not yet spec'd, I expect it will be renamed
408 multi method trim-trailing() is export {
ad2afb5 @moritz stringify self in Cool.trim-{leading,trailing}
moritz authored
409 if ~self ~~ /^(.*\S)\s*$/ {
ff4ced6 @colomon Initial stabs at Any.trim and Any.rindex. Neither works, and rindex …
colomon authored
410 ~$/[0];
f483b59 @colomon Fix shortcomings in the previous trim-leading and trim-trailing imple…
colomon authored
411 } elsif self ~~ /^\s*$/ {
412 "";
413 }
414 else {
ff4ced6 @colomon Initial stabs at Any.trim and Any.rindex. Neither works, and rindex …
colomon authored
415 self;
416 }
417 }
418
8564837 @colomon Add trim-leading and trim-trailing, and reimplement trim in terms of …
colomon authored
419 # TODO: signature not fully specced in S32 yet
420 multi method trim() is export {
421 self.trim-leading.trim-trailing;
422 }
423
12c5229 @colomon Tweak Cool.words, implement Cool.lines.
colomon authored
424 multi method words(Str $input: Int $limit = *) {
425 $input.comb( / \S+ /, $limit );
426 }
427
428 our multi method lines(Str $input: Int $limit = Inf) {
429 $input.comb( / ^^ \N* /, $limit );
f2ba537 @colomon Implement Any.words.
colomon authored
430 }
431
4fc3af7 @colomon Add protos for uc, lc, ucfirst, and lcfirst.
colomon authored
432 our Str multi method uc() {
1d7ec80 @jnthn Add some of Any-str.pm back in.
jnthn authored
433 ~(pir::upcase__SS(self))
434 }
435
4fc3af7 @colomon Add protos for uc, lc, ucfirst, and lcfirst.
colomon authored
436 our Str multi method ucfirst() {
1d7ec80 @jnthn Add some of Any-str.pm back in.
jnthn authored
437 self gt '' ?? self.substr(0,1).uc ~ self.substr(1) !! ""
438 }
abd99af @jnthn Add back sprintf.
jnthn authored
439
440 our Str multi method sprintf(*@args) {
441 my $result;
442 try {
443 $result = pir::sprintf__SSP(~self, (|@args)!PARROT_POSITIONALS);
444 }
445 $! ?? fail( "Insufficient arguments supplied to sprintf") !! $result
446 }
36c5464 @moritz switch file tests to $filename.IO ~~ :e; implement IO.z
moritz authored
447
448 method IO() {
449 ::IO.new(path => ~self);
450 }
1d7ec80 @jnthn Add some of Any-str.pm back in.
jnthn authored
451 }
452
f5b18c9 @jnthn More removal of our; this is probably so far as we can go for now.
jnthn authored
453 multi sub ord($string) {
7fc4854 @moritz make ord() and chr() work with named args
moritz authored
454 $string.ord;
455 }
456
f5b18c9 @jnthn More removal of our; this is probably so far as we can go for now.
jnthn authored
457 proto ord($string) {
7fc4854 @moritz make ord() and chr() work with named args
moritz authored
458 $string.ord;
459 }
460
da89dd6 @unobe Remove &infix:<x> in cheats and update version in Any-str.pm
unobe authored
461 our Str proto sub infix:<x>($str, $n) {
1d7ec80 @jnthn Add some of Any-str.pm back in.
jnthn authored
462 $n > 0 ?? ~(pir::repeat__SSI($str, $n)) !! ''
463 }
464
f6b45df @moritz infix:<cmp>, leg, <=>
moritz authored
465 our multi sub infix:<cmp>($a, $b) {
3f202d5 @pmichaud More range improvements. All spectests pass.
pmichaud authored
466 return Order::Increase if $a eqv -Inf || $b eqv Inf;
467 return Order::Decrease if $a eqv Inf || $b eqv -Inf;
035efb0 @pmichaud Refactor some comparison operators to avoid unnecessary blocks and
pmichaud authored
468 $a lt $b ?? Order::Increase !! ($a gt $b ?? Order::Decrease !! Order::Same);
f6b45df @moritz infix:<cmp>, leg, <=>
moritz authored
469 }
470
471 our multi sub infix:<leg>($a, $b) {
472 ~$a cmp ~$b
473 }
474
8aff115 @moritz fix split() with zero-width matches; also run two more test files
moritz authored
475 multi split ( $delimiter, $input, $limit = *, :$all ) {
476 $input.split($delimiter, $limit, :$all);
b7fb2e1 @jnthn Revert "Revert "Merge branch 'ng' of github.com:rakudo/rakudo into ng""
jnthn authored
477 }
478
8827d07 @patrickas Added sub comb
patrickas authored
479 our List multi comb ( Regex $matcher, Str $input, Int $limit = Inf ) {
480 $input.comb($matcher , $limit );
481 }
482
f5b18c9 @jnthn More removal of our; this is probably so far as we can go for now.
jnthn authored
483 multi sub sprintf($str as Str, *@args) {
abd99af @jnthn Add back sprintf.
jnthn authored
484 $str.sprintf(|@args)
485 }
f6b45df @moritz infix:<cmp>, leg, <=>
moritz authored
486
f5b18c9 @jnthn More removal of our; this is probably so far as we can go for now.
jnthn authored
487 proto sub uc($string) { $string.uc; }
488 proto sub ucfirst($string) { $string.ucfirst; }
489 proto sub lc($string) { $string.lc; }
490 proto sub lcfirst($string) { $string.lcfirst; }
491 proto sub capitalize($string) { $string.capitalize; }
4fc3af7 @colomon Add protos for uc, lc, ucfirst, and lcfirst.
colomon authored
492
1d7ec80 @jnthn Add some of Any-str.pm back in.
jnthn authored
493 # vim: ft=perl6
Something went wrong with that request. Please try again.