From 23291f0a7104f790bc1309154864e97a8522c428 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 12 Aug 2009 12:12:07 +0100 Subject: [PATCH] Island/arch names which uniquely match initial substring are also ok --- yarrg/web/routetextstring | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/yarrg/web/routetextstring b/yarrg/web/routetextstring index 4202ce9..70d6144 100644 --- a/yarrg/web/routetextstring +++ b/yarrg/web/routetextstring @@ -41,22 +41,29 @@ if ($format =~ 'json') { foreach my $each (split m#[/|,]#, $string) { $each =~ s/^\s*//; $each =~ s/\s*$//; $each =~ s/\s+/ /g; next if !length $each; - my $pat= "\%$each\%"; - my $nrows= $sth->execute($pat,$pat); my $err= sub { my $msg= sprintf $_[0], encode_entities($each); $output_wrong->($msg); $m->abort(); }; - my $results= $sth->fetchall_arrayref(); - if (!@$results) { - $err->('no island or arch matches "%s"'); - } elsif (@$results > 3) { - $err->(' '); - } elsif (@$results > 1) { - my @m= map { $_->[2] } @$results; - $err->('ambiguous island or arch "%s", could be '. - join(', ', @m)); + my @m; + my $results; + foreach my $pat ("$each\%", "\%$each\%") { + $sth->execute($pat,$pat); + $results= $sth->fetchall_arrayref(); + last if @$results==1; + push @m, @$results; + $results= undef; + } + if (!$results) { + if (!@m) { + $err->('no island or arch matches "%s"'); + } elsif (@m > 3) { + $err->(' '); + } else { + $err->('ambiguous island or arch "%s", could be '. + join(', ', map { $_->[2] } @m)); + } } push @results, $results->[0]; } -- 2.30.2