Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/p6.p6 Secret

Created March 10, 2018 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/da3b0ceef133b9ff505803f8483b2f05 to your computer and use it in GitHub Desktop.
Save zoffixznet/da3b0ceef133b9ff505803f8483b2f05 to your computer and use it in GitHub Desktop.
sub shortify($n) {
while (my int $colon := nqp::rindex($n, '::')) != -1 {
my int $paren := nqp::rindex($n, '[', $colon-1);
my int $comma := nqp::rindex($n, ',', $colon-1);
my int $chop-start := $paren < 0 && $comma < 0
?? 0 !! $paren != -1 && $paren < $comma ?? $comma+1 !! $paren+1;
$n := nqp::substr($n, 0, $chop-start) ~ nqp::substr($n, $colon+2);
}
$n
}
say(shortify('CArray[Bars::int32]'));
say(shortify('NativeCall::Types::CArray[NativeCall::Types::Pointer[int32]]'));
say(shortify('Hash[Foo::Bar::Ber[Foo::Bar::Ber[int32]],Foo::Bar::Ber[int32]]'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment