Last active
May 3, 2018 13:20
-
-
Save ildar-shaimordanov/c36cf27973d34a338c93b38ec879ff23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# another solution by this link | |
# https://stackoverflow.com/q/17318289/3627676 | |
use strict; | |
use warnings; | |
sub decamelize { | |
my $s = shift; | |
my $sep = shift || "_"; | |
my $r = @_ | |
? sprintf "(%s|[A-Z])", join "|", map { uc quotemeta } @_ | |
: "([A-Z]+?)(?=[A-Z]?[^A-Z])"; | |
# : "([A-Z])"; | |
$s =~ s/$r/$sep\L$1/g; | |
return $s; | |
} | |
sub camelize { | |
my $s = shift; | |
my $sep = shift || "_"; | |
my $r = @_ | |
? sprintf "(%s|[a-z])", join "|", map { lc quotemeta } @_ | |
: "([a-z])"; | |
$s =~ s/$sep$r/\U$1/g; | |
return $s; | |
} | |
my @abbr = qw/ascii ufo/; | |
for my $s ( qw( | |
LogUFOType | |
PrintASCIICode | |
zIndex | |
ZIndex | |
) ) { | |
my $t = decamelize $s, "-", @abbr; | |
my $u = camelize $t, "-", @abbr; | |
printf "%20s\t%20s\t%20s\n", $s, $t, $u; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment