You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
1.9 KiB

  1. # -*- cperl -*-
  2. # Copyright (C) 2004-2008 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. # This is a library file used by the Perl version of mysql-test-run,
  17. # and is part of the translation of the Bourne shell script with the
  18. # same name.
  19. package mtr_match;
  20. use strict;
  21. use base qw(Exporter);
  22. our @EXPORT= qw(mtr_match_prefix
  23. mtr_match_extension
  24. mtr_match_substring);
  25. #
  26. # Match a prefix and return what is after the prefix
  27. #
  28. sub mtr_match_prefix ($$) {
  29. my $string= shift;
  30. my $prefix= shift;
  31. if ( $string =~ /^\Q$prefix\E(.*)$/ ) # strncmp
  32. {
  33. return $1;
  34. }
  35. else
  36. {
  37. return undef; # NULL
  38. }
  39. }
  40. #
  41. # Match extension and return the name without extension
  42. #
  43. sub mtr_match_extension ($$) {
  44. my $file= shift;
  45. my $ext= shift;
  46. if ( $file =~ /^(.*)\.\Q$ext\E$/ ) # strchr+strcmp or something
  47. {
  48. return $1;
  49. }
  50. else
  51. {
  52. return undef; # NULL
  53. }
  54. }
  55. #
  56. # Match a substring anywere in a string
  57. #
  58. sub mtr_match_substring ($$) {
  59. my $string= shift;
  60. my $substring= shift;
  61. if ( $string =~ /(.*)\Q$substring\E(.*)$/ ) # strncmp
  62. {
  63. return $1;
  64. }
  65. else
  66. {
  67. return undef; # NULL
  68. }
  69. }
  70. sub mtr_match_any_exact ($$) {
  71. my $string= shift;
  72. my $mlist= shift;
  73. foreach my $m (@$mlist)
  74. {
  75. if ( $string eq $m )
  76. {
  77. return 1;
  78. }
  79. }
  80. return 0;
  81. }
  82. 1;