~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to mysql-test/lib/mtr_match.pm

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- cperl -*-
 
2
# Copyright (C) 2004-2006 MySQL AB
 
3
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; version 2 of the License.
 
7
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
16
 
 
17
# This is a library file used by the Perl version of mysql-test-run,
 
18
# and is part of the translation of the Bourne shell script with the
 
19
# same name.
 
20
 
 
21
package mtr_match;
 
22
use strict;
 
23
 
 
24
use base qw(Exporter);
 
25
our @EXPORT= qw(mtr_match_prefix
 
26
                mtr_match_extension
 
27
                mtr_match_substring);
 
28
 
 
29
#
 
30
# Match a prefix and return what is after the prefix
 
31
#
 
32
sub mtr_match_prefix ($$) {
 
33
  my $string= shift;
 
34
  my $prefix= shift;
 
35
 
 
36
  if ( $string =~ /^\Q$prefix\E(.*)$/ ) # strncmp
 
37
  {
 
38
    return $1;
 
39
  }
 
40
  else
 
41
  {
 
42
    return undef;               # NULL
 
43
  }
 
44
}
 
45
 
 
46
 
 
47
#
 
48
# Match extension and return the name without extension
 
49
#
 
50
sub mtr_match_extension ($$) {
 
51
  my $file= shift;
 
52
  my $ext=  shift;
 
53
 
 
54
  if ( $file =~ /^(.*)\.\Q$ext\E$/ ) # strchr+strcmp or something
 
55
  {
 
56
    return $1;
 
57
  }
 
58
  else
 
59
  {
 
60
    return undef;                       # NULL
 
61
  }
 
62
}
 
63
 
 
64
 
 
65
#
 
66
# Match a substring anywere in a string
 
67
#
 
68
sub mtr_match_substring ($$) {
 
69
  my $string= shift;
 
70
  my $substring= shift;
 
71
 
 
72
  if ( $string =~ /(.*)\Q$substring\E(.*)$/ ) # strncmp
 
73
  {
 
74
    return $1;
 
75
  }
 
76
  else
 
77
  {
 
78
    return undef;               # NULL
 
79
  }
 
80
}
 
81
 
 
82
 
 
83
sub mtr_match_any_exact ($$) {
 
84
  my $string= shift;
 
85
  my $mlist=  shift;
 
86
 
 
87
  foreach my $m (@$mlist)
 
88
  {
 
89
    if ( $string eq $m )
 
90
    {
 
91
      return 1;
 
92
    }
 
93
  }
 
94
  return 0;
 
95
}
 
96
 
 
97
1;