Skip to content

Commit

Permalink
handle [array names] with no pattern.
Browse files Browse the repository at this point in the history
  • Loading branch information
coke committed Jun 25, 2010
1 parent 2018690 commit 9128ec7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
30 changes: 18 additions & 12 deletions src/Partcl/commands/array.pm
Expand Up @@ -116,19 +116,25 @@ my sub get($array, $pattern = '*') {

my sub names($array, $mode="-glob", $pattern="" ) {
my $result := pir::new__ps('TclList');
my $globber := StringGlob::Compiler.compile($pattern);
my $ARE := ARE::Compiler.compile($pattern);
for $array -> $key {
my $match := 0;
if ($mode eq "-glob" && ?Regex::Cursor.parse($key, :rule($globber), :c(0))) {
$match := 1;
} elsif ($mode eq "-glob" && ?Regex::Cursor.parse($key, :rule($ARE), :c(0))) {
$match := 1;
} elsif ($mode eq "-exact" && $key eq $pattern) {
$match := 1;
if $pattern eq "" {
for $array -> $key {
$result.push($key)
}
$result.push($key) if $match;
}
} else {
my $globber := StringGlob::Compiler.compile($pattern);
my $ARE := ARE::Compiler.compile($pattern);
for $array -> $key {
my $match := 0;
if $mode eq "-glob" && ?Regex::Cursor.parse($key, :rule($globber), :c(0)) {
$match := 1;
} elsif $mode eq "-glob" && ?Regex::Cursor.parse($key, :rule($ARE), :c(0)) {
$match := 1;
} elsif $mode eq "-exact" && $key eq $pattern {
$match := 1;
}
$result.push($key) if $match;
}
}
$result;
}

Expand Down
6 changes: 3 additions & 3 deletions t/cmd_array.t
Expand Up @@ -207,13 +207,13 @@ eval_is {
eval_is {
catch {unset a}
array names a
} {} {array names, no array} {TODO NQPRX}
} {} {array names, no array}

eval_is {
catch {unset a}
array set a [list {b c} a]
array names a
} {{b c}} {array names, insure list results} {TODO NQPRX}
} {{b c}} {array names, insure list results}

eval_is {array names a b c} \
{bad option "b": must be -exact, -glob, or -regexp} \
Expand All @@ -227,7 +227,7 @@ eval_is {
catch {unset a}
set a(monkey) see
array names a
} {monkey} {array names, no pattern} {TODO NQPRX}
} {monkey} {array names, no pattern}

eval_is {
catch {unset a}
Expand Down

0 comments on commit 9128ec7

Please sign in to comment.