X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FUtil.pm;h=bf2e9ff41050d7c728b0b296bbe0dbbb90661b2d;hb=549f187d3a2b1d15f96c4556714666ed954447bb;hp=fdcc080cf766b3b921e5359463005e3233d4550c;hpb=5e9aaf1c3e83467ed4f6550627f8c7e6ec6fa811;p=kivitendo-erp.git diff --git a/SL/Util.pm b/SL/Util.pm index fdcc080cf..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); +our @EXPORT_OK = qw(_hashify camelify snakify trim); sub _hashify { my $keep = shift; @@ -18,6 +18,26 @@ sub _hashify { ((1 + $keep) == scalar(@_)) && ((ref($_[$keep]) || '') eq 'HASH') ? %{ $_[$keep] } : @_[$keep..scalar(@_) - 1]); } +sub camelify { + my ($str) = @_; + $str =~ s/_+([[:lower:]])/uc($1)/ge; + ucfirst $str; +} + +sub snakify { + my ($str) = @_; + $str =~ s/_([[:upper:]])/'_' . lc($1)/ge; + $str =~ s/(? + +Returns C<$string> converted from underscore-style to +camel-case-style, e.g. for the string C it will +return C. + +L does the reverse. + +=item C + +Returns C<$string> converted from camel-case-style to +underscore-style, e.g. for the string C it will +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