summaryrefslogtreecommitdiff
path: root/fml/lib/IO
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-04-15 08:41:59 +0000
committerfukachan <fukachan>2001-04-15 08:41:59 +0000
commit9c982c205792c28dfd493993b363545f3e676b01 (patch)
tree80dda3483e851eedcaaca73ec3968a3c9e3466be /fml/lib/IO
parentc2836d0fe66321cb27e9b56967fdc732b4e880cc (diff)
downloadfml8-9c982c205792c28dfd493993b363545f3e676b01.tar.gz
fml8-9c982c205792c28dfd493993b363545f3e676b01.tar.bz2
fml8-9c982c205792c28dfd493993b363545f3e676b01.zip
implement find($regexp [,$args])
search $regexp in C<map> and return the line which matches C<$regexp>. It searches C<$regexp> in case insenssitive by default. You can change the search behaviour by C<$args> (HASH REFERENCE).
Diffstat (limited to 'fml/lib/IO')
-rw-r--r--fml/lib/IO/MapAdapter.pm39
1 files changed, 38 insertions, 1 deletions
diff --git a/fml/lib/IO/MapAdapter.pm b/fml/lib/IO/MapAdapter.pm
index a4bd118f..28da523c 100644
--- a/fml/lib/IO/MapAdapter.pm
+++ b/fml/lib/IO/MapAdapter.pm
@@ -5,7 +5,7 @@
# redistribute it and/or modify it under the same terms as Perl itself.
#
# $Id$
-# $FML: MapAdapter.pm,v 1.26 2001/04/03 09:45:45 fukachan Exp $
+# $FML: MapAdapter.pm,v 1.27 2001/04/08 13:25:39 fukachan Exp $
#
package IO::MapAdapter;
@@ -315,6 +315,43 @@ sub replace
}
+=head2 C<find($regexp [,$args])>
+
+search $regexp in C<map> and return the line which matches C<$regexp>.
+It searches C<$regexp> in case insenssitive by default.
+You can change the search behaviour by C<$args> (HASH REFERENCE).
+
+ $args = {
+ case_sensitive => 1, # case senssitive
+ };
+
+=cut
+
+sub find
+{
+ my ($self, $regexp, $args) = @_;
+ my $case_sensitive = $args->{ case_sensitive } ? 1 : 0;
+ my $x;
+
+ # forward the request to SUPER class
+ if ($self->SUPER::can('_find')) { $self->_find($regexp, $args);}
+
+ # search regexp by reading the specified map.
+ $self->open;
+ while (defined ($x = $self->get_next_value())) {
+ if ($case_sensitive) {
+ last if $x =~ /$regexp/;
+ }
+ else {
+ last if $x =~ /$regexp/i;
+ }
+ }
+ $self->close;
+ $x;
+}
+
+
+
# Descriptions: destructor
# request is forwarded to close() method.
# Arguments: $self $args