X-Git-Url: http://wagnertech.de/git?p=kivitendo-erp.git;a=blobdiff_plain;f=SL%2FUtil.pm;fp=SL%2FUtil.pm;h=bf2e9ff41050d7c728b0b296bbe0dbbb90661b2d;hp=2fdd9c1f61d78089f9661735f1083f79216a6736;hb=53593baa211863fbf66540cf1bcc36c8fb37257f;hpb=deb4d2dbb676d7d6f69dfe7815d6e0cb09bd4a44 diff --git a/SL/Util.pm b/SL/Util.pm index 2fdd9c1f6..bf2e9ff41 100644 --- a/SL/Util.pm +++ b/SL/Util.pm @@ -6,7 +6,7 @@ use parent qw(Exporter); use Carp; -our @EXPORT_OK = qw(_hashify camelify snakify); +our @EXPORT_OK = qw(_hashify camelify snakify trim); sub _hashify { my $keep = shift; @@ -31,6 +31,13 @@ sub snakify { lc $str; } +sub trim { + my $value = shift; + $value =~ s{^ \p{WSpace}+ }{}xg if defined($value); + $value =~ s{ \p{WSpace}+ $}{}xg if defined($value); + return $value; +} + 1; __END__ @@ -90,6 +97,14 @@ return C. L does the reverse. +=item C + +Removes all leading and trailing whitespaces from C<$string> and +returns it. Whitespaces within the string won't be changed. + +This function considers everything matching the Unicode character +property "Whitespace" (C) to be a whitespace. + =back =head1 BUGS