Skip to content

Commit

Permalink
Util: add a flags alphabet
Browse files Browse the repository at this point in the history
...so you can have more flags in your life. This was totally Joe's idea
but he did not want to perl enough to get it into Synergy, so I helped
(read: he nerdsniped me).
  • Loading branch information
mmcclimon committed Mar 26, 2022
1 parent 697cc4c commit 2ee4231
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use warnings;

use 5.028000;

use ExtUtils::MakeMaker 6.78;
use ExtUtils::MakeMaker;

use File::ShareDir::Install;
$File::ShareDir::Install::INCLUDE_DOTFILES = 1;
Expand All @@ -16,7 +16,7 @@ my %WriteMakefileArgs = (
"ABSTRACT" => "synergy's brain",
"AUTHOR" => "Michael McClimon <michael\@mcclimon.org>",
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => "6.78",
"ExtUtils::MakeMaker" => 0,
"File::ShareDir::Install" => "0.06"
},
"DISTNAME" => "Synergy",
Expand Down Expand Up @@ -60,6 +60,7 @@ my %WriteMakefileArgs = (
"Lingua::EN::Inflect" => 0,
"List::AllUtils" => 0,
"List::Util" => 0,
"Locale::Codes" => 0,
"Log::Dispatchouli" => "2.019",
"Log::Dispatchouli::Global" => 0,
"MIME::Base64" => 0,
Expand Down Expand Up @@ -160,6 +161,7 @@ my %FallbackPrereqs = (
"Lingua::EN::Inflect" => 0,
"List::AllUtils" => 0,
"List::Util" => 0,
"Locale::Codes" => 0,
"Log::Dispatchouli" => "2.019",
"Log::Dispatchouli::Global" => 0,
"MIME::Base64" => 0,
Expand Down
1 change: 1 addition & 0 deletions cpanfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ requires "Linear::Client" => "0";
requires "Lingua::EN::Inflect" => "0";
requires "List::AllUtils" => "0";
requires "List::Util" => "0";
requires "Locale::Codes" => "0";
requires "Log::Dispatchouli" => "2.019";
requires "Log::Dispatchouli::Global" => "0";
requires "MIME::Base64" => "0";
Expand Down
30 changes: 30 additions & 0 deletions lib/Synergy/Util.pm
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,36 @@ sub _load_alphabets {
}
return $transliterated;
},
flags => sub ($s) {
require Locale::Codes;

my %char_for = qw(
a ๐Ÿ‡ฆ b ๐Ÿ‡ง c ๐Ÿ‡จ d ๐Ÿ‡ฉ e ๐Ÿ‡ช f ๐Ÿ‡ซ g ๐Ÿ‡ฌ h ๐Ÿ‡ญ i ๐Ÿ‡ฎ
j ๐Ÿ‡ฏ k ๐Ÿ‡ฐ l ๐Ÿ‡ฑ m ๐Ÿ‡ฒ n ๐Ÿ‡ณ o ๐Ÿ‡ด p ๐Ÿ‡ต q ๐Ÿ‡ถ r ๐Ÿ‡ท
s ๐Ÿ‡ธ t ๐Ÿ‡น u ๐Ÿ‡บ v ๐Ÿ‡ป w ๐Ÿ‡ผ x ๐Ÿ‡ฝ y ๐Ÿ‡พ z ๐Ÿ‡ฟ
);

my $lc = Locale::Codes->new('country');
my %is_country = map {; $_ => 1 } $lc->all_codes('alpha-2');

my $out = '';

for (my $i = 0; $i < (length $s) - 1; $i++) {
my $digraph = lc substr $s, $i, 2;

if ($is_country{$digraph}) {
$out .= $char_for{$_} for split //, $digraph;
$i++; # no double-counting
} else {
$out .= substr $s, $i, 1;
}

# make sure we don't drop the last char the last char if we need to
$out .= substr $s, -1, 1 if $i == (length $s) - 2;
}

return $out;
},

# Further wonky styles, which come from github.com/rjbs/misc/unicode-style,
# are left up to wonkier people than me. -- rjbs, 2019-02-12
Expand Down

0 comments on commit 2ee4231

Please sign in to comment.