X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FUtil.pm;h=2fdd9c1f61d78089f9661735f1083f79216a6736;hb=71ada638068acc8b1481b7392bc0511fa627647e;hp=fdcc080cf766b3b921e5359463005e3233d4550c;hpb=5e9aaf1c3e83467ed4f6550627f8c7e6ec6fa811;p=kivitendo-erp.git diff --git a/SL/Util.pm b/SL/Util.pm index fdcc080cf..2fdd9c1f6 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); sub _hashify { my $keep = shift; @@ -18,6 +18,19 @@ 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. + =back =head1 BUGS