X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=inline;f=SL%2FUtil.pm;h=9022d939b7b2d60592fb49c13bb380f14e4ca675;hb=f9a93e326337ed219de49f575c02e5a8cb36a1b6;hp=2fdd9c1f61d78089f9661735f1083f79216a6736;hpb=a23454bb1b039a31b7f77710ff663fa9152d530c;p=kivitendo-erp.git diff --git a/SL/Util.pm b/SL/Util.pm index 2fdd9c1f6..9022d939b 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,12 @@ sub snakify { lc $str; } +sub trim { + my $value = shift; + $value =~ s{^ \p{WSpace}+ | \p{WSpace}+ $}{}xg if defined($value); + return $value; +} + 1; __END__ @@ -90,6 +96,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