Bug 17302: Add Koha::Util::Normalize for normalization functions
[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
45     my $string = uc shift;
46
47     $string =~ s/[.;:,\]\[\)\(\/'"]//g;
48     $string =~ s/^\s+//;
49     $string =~ s/\s+$//;
50     $string =~ s/\s+/ /g;
51
52     return $string;
53 }
54
55 =head2 remove_spaces
56
57 Normalization function removing spaces
58
59 =cut
60
61 sub remove_spaces {
62
63     my $string = shift;
64
65     $string =~ s/\s+//g;
66
67     return $string;
68 }
69
70 =head2 upper_case
71
72 Normalization function converting characters into upper-case
73
74 =cut
75
76 sub upper_case {
77
78     my $string = uc shift;
79
80     return $string;
81 }
82
83 =head2 lower_case
84
85 Normalization function converting characters into lower-case
86
87 =cut
88
89 sub lower_case {
90
91     my $string = lc shift;
92
93     return $string;
94 }
95
96 1;
97 __END__
98
99 =head1 AUTHOR
100
101 Koha Development Team <http://koha-community.org/>
102
103 Tomas Cohen Arazi <tomascohen@theke.io>
104
105 =cut