Guest User

Untitled

a guest
May 21st, 2018
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. use utf8;
  5.  
  6. use Test::More;
  7.  
  8.  
  9. sub camelize {
  10. my ($s) = @_;
  11. $s =~ s{(\w+)}{
  12. ($a = lc $1) =~ s<(^[a-z]|_[a-z])><
  13. ($b = uc $1) =~ s/^_//;
  14. $b;
  15. >eg;
  16. $a;
  17. }eg;
  18. $s;
  19. }
  20.  
  21. sub decamelize {
  22. my ($s) = @_;
  23. $s =~ s{(\w+)}{
  24. ($a = $1) =~ s<(^[A-Z]|(?![a-z])[A-Z])><
  25. "_" . lc $1
  26. >eg;
  27. substr $a, 1;
  28. }eg;
  29. $s;
  30. }
  31.  
  32.  
  33.  
  34.  
  35. is camelize('snake_case'), 'SnakeCase';
  36. is decamelize('CamelCase'), 'camel_case';
  37. is decamelize(camelize('snake_case')), 'snake_case';
  38. is camelize(decamelize('CamelCase')), 'CamelCase';
  39.  
  40. done_testing
  41. __END__
  42.  
  43. =head1 NAME
  44.  
  45. perl.pl - NO DESCRIPTION YET.
  46.  
  47.  
  48. =head1 SYNOPSIS
  49.  
  50.  
  51. =head1 OPTIONS
  52.  
  53.  
  54. =head1 AUTHOR
  55.  
  56. tyru <tyru.exe@gmail.com>
Add Comment
Please, Sign In to add comment