Skip to content

Commit

Permalink
- Fixed the String.count() method when it's called with a regular exp…
Browse files Browse the repository at this point in the history
…ression.

Example:
	say "the three truths".count(/th/);	# prints: 3
	say "ababababab".count(/abab/);		# prints: 2
  • Loading branch information
trizen committed Dec 29, 2015
1 parent 33df118 commit 8affc32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/Sidef/Types/String/String.pm
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ package Sidef::Types::String::String {

if (ref($arg) eq 'Sidef::Types::Regex::Regex') {
my $regex = $arg->{regex};
$counter += CORE::length($1) while $s =~ /($regex)/g;
++$counter while $s =~ /$regex/g;
return Sidef::Types::Number::Number->new($counter);
}
elsif (ref($arg) eq 'Sidef::Types::Block::Block') {
Expand Down
12 changes: 6 additions & 6 deletions scripts/Graphical/sierpinski_triangle_graphical.sf
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class Array {
var row = self[i];
img.moveTo(0, j);
loop {
if ((var sp = row.count(/^\s+/)) > 0) {
row.substr!(sp);
if (var sp = row.match(/^\s+/)) {
row.substr!(sp.pos.last);
img.fgcolor(bgcolor);
img.line(scale * sp);
img.line(scale * sp.pos.last);
}
elsif ((var nsp = row.count(/^\S+/)) > 0) {
row.substr!(nsp);
elsif (var nsp = row.match(/^\S+/)) {
row.substr!(nsp.pos.last);
img.fgcolor(fgcolor);
img.line(scale * nsp);
img.line(scale * nsp.pos.last);
}
else {
break;
Expand Down

0 comments on commit 8affc32

Please sign in to comment.