Bug 20438: Allow uninstalling plugins not implementing the 'uninstall' method
[koha.git] / Koha / Util / Normalize.pm
1 package Koha::Util::Normalize;
2
3 # Copyright 2016 Koha Development Team
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use Modern::Perl;
21
22 use parent qw( Exporter );
23
24 our @EXPORT = qw(
25   legacy_default
26   remove_spaces
27   upper_case
28   lower_case
29 );
30
31 =head1 NAME
32
33 Koha::Util::Normalize - utility class with string normalization routines
34
35 =head1 METHODS
36
37 =head2 legacy_default
38
39 Default normalization function
40
41 =cut
42
43 sub legacy_default {
44     my ( $string ) = @_;
45     return if !defined( $string );
46
47     $string = uc $string;
48
49     $string =~ s/[.;:,\]\[\)\(\/'"]//g;
50     $string =~ s/^\s+//;
51     $string =~ s/\s+$//;
52     $string =~ s/\s+/ /g;
53
54     return $string;
55 }
56
57 =head2 remove_spaces
58
59 Normalization function removing spaces
60
61 =cut
62
63 sub remove_spaces {
64     my ( $string ) = @_;
65     return if !defined( $string );
66
67     $string =~ s/\s+//g;
68
69     return $string;
70 }
71
72 =head2 upper_case
73
74 Normalization function converting characters into upper-case
75
76 =cut
77
78 sub upper_case {
79     my ( $string ) = @_;
80     return if !defined( $string );
81
82     $string = uc $string;
83
84     return $string;
85 }
86
87 =head2 lower_case
88
89 Normalization function converting characters into lower-case
90
91 =cut
92
93 sub lower_case {
94     my ( $string ) = @_;
95     return if !defined( $string );
96
97     $string = lc $string;
98
99     return $string;
100 }
101
102 1;
103 __END__
104
105 =head1 AUTHOR
106
107 Koha Development Team <http://koha-community.org/>
108
109 Tomas Cohen Arazi <tomascohen@theke.io>
110
111 =cut