Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / SL / Util.pm
index 2fdd9c1..bf2e9ff 100644 (file)
@@ -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<even_worse_example>.
 
 L</camilify> does the reverse.
 
+=item C<trim $string>
+
+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<WSpace>) to be a whitespace.
+
 =back
 
 =head1 BUGS