Skip to content

Commit

Permalink
Merge branch 'master' into str_split_in_setting
Browse files Browse the repository at this point in the history
  • Loading branch information
moritz committed Feb 23, 2009
2 parents 1fe71b8 + 108dfb5 commit 0e7dd5e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 48 deletions.
12 changes: 7 additions & 5 deletions Test.pm
Expand Up @@ -51,10 +51,10 @@ multi sub pass($desc) is export() {
}

multi sub ok(Object $cond, $desc) is export() {
proclaim($cond, $desc);
proclaim(?$cond, $desc);
}

multi sub ok(Object $cond) is export() { ok($cond, ''); }
multi sub ok(Object $cond) is export() { ok(?$cond, ''); }


multi sub nok(Object $cond, $desc) is export() {
Expand All @@ -66,7 +66,7 @@ multi sub nok(Object $cond) is export() { nok(!$cond, ''); }

multi sub is(Object $got, Object $expected, $desc) is export() {
my $test = $got eq $expected;
proclaim($test, $desc);
proclaim(?$test, $desc);
}

multi sub is(Object $got, Object $expected) is export() { is($got, $expected, ''); }
Expand All @@ -81,10 +81,12 @@ multi sub isnt(Object $got, Object $expected) is export() { isnt($got, $expected

multi sub is_approx(Object $got, Object $expected, $desc) is export() {
my $test = abs($got - $expected) <= 0.00001;
proclaim($test, $desc);
proclaim(?$test, $desc);
}

multi sub is_approx($got, $expected) is export() { is_approx($got, $expected, ''); }
multi sub is_approx(Object $got, Object $expected) is export() {
is_approx($got, $expected, '');
}

multi sub todo($reason, $count) is export() {
$todo_upto_test_num = $num_of_tests_run + $count;
Expand Down
45 changes: 2 additions & 43 deletions src/builtins/any-str.pir
Expand Up @@ -163,48 +163,6 @@ Remove leading and trailing whitespace from a string.
.return(s)
.end
=item comb()
Partial implementation for now, returns a list of strings
(instead of a list of match objects).
=cut
.sub 'comb' :method :multi(_)
.param pmc regex
.param int count :optional
.param int has_count :opt_flag
.local pmc retv, match
.local string s
.local int pos
retv = 'list'()
s = self
pos = 0
do_match:
match = regex(s, 'continue' => pos)
unless match goto done
unless has_count goto skip_count
dec count
if count < 0 goto done
skip_count:
# shouldn't have to coerce to Str here, but see RT #55962
$S0 = match
retv.'push'($S0)
$I0 = match.'to'()
if pos == $I0 goto zero_width
pos = $I0
goto do_match

zero_width:
inc pos
goto do_match
done:
.return(retv)
.end

=item ':d'()
our Bool multi Str::':d' ( Str $filename )
Expand Down Expand Up @@ -318,7 +276,8 @@ Returns the invocant formatted by an implicit call to C<sprintf>.
s = self
check_substring:
if substring goto substring_search
$I1 = length substring
if $I1 goto substring_search
$I0 = length s
if pos < $I0 goto done
pos = $I0
Expand Down
15 changes: 15 additions & 0 deletions src/setting/Str.pm
Expand Up @@ -32,6 +32,21 @@ class Str is also {
$prev = $pos + $delimiter.chars;
}
take self.substr($prev);

our List multi method comb (Code $matcher = /\S+/, $limit = *) {
my $l = $limit ~~ Whatever ?? Inf !! $limit;
# currently we use a copy of self and destroy it piece by piece.
# the preferred way of doing it is using self, not destroying it,
# and use the :pos modifier to the regex. That way the offsets into
# self will be right
my $s = self;
return gather {
while $l > 0 && $s ~~ $matcher {
# if we have captures, return the actual match object
take @($/) || %($/) ?? $/.clone !! ~$/;
$l--;
$s.=substr([max] 1, $/.to);
}
}
}
}
Expand Down

0 comments on commit 0e7dd5e

Please sign in to comment.