Last active
February 6, 2017 09:07
-
-
Save samcv/98e9628db3232a3ced4e41389bfef9ea 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
use nqp; | |
class Collation is export { | |
has int $.collation-level = 15; | |
has $!Country = 'International'; | |
method gist { | |
"collation-level => $!collation-level, Country => $!Country, " ~ | |
"Language => None, primary => {self.primary}, secondary => {self.secondary}, " ~ | |
"tertiary => {self.tertiary}, quaternary => {self.quaternary}" | |
} | |
multi method set (Int :$collation-level!) { | |
$!collation-level = $collation-level; | |
} | |
multi method set (Bool :$primary = self.primary, | |
Bool :$secondary = self.secondary, Bool :$tertiary = self.tertiary, | |
Bool :$quaternary = self.quaternary) | |
{ | |
my int $i = 0; | |
$i += 1 if $primary; | |
$i += 2 if $secondary; | |
$i += 4 if $tertiary; | |
$i += 8 if $quaternary; | |
$!collation-level = $i; | |
} | |
method primary { so $!collation-level +& 1 } | |
method secondary { so $!collation-level +& 2 } | |
method tertiary { so $!collation-level +& 4 } | |
method quaternary { so $!collation-level +& 8 } | |
} | |
PROCESS::<$COLLATION> = Collation.new; | |
proto sub infix:<coll>(|) { * } | |
multi sub infix:<coll>(Str:D \a, Str:D \b) returns Order:D { | |
ORDER( | |
nqp::unicmp_s( | |
nqp::unbox_s(a), nqp::unbox_s(b), $*COLLATION.Collation-Level,0,0)) | |
} | |
sub test-it { | |
$*COLLATION.set(:primary(False)); | |
#$*COLLATION.set(:collation-level(5)); | |
#$*COLLATION.set(:what); | |
say $*COLLATION; | |
say $*COLLATION.perl; | |
#my $c = Collation.new(collation-level => 5); | |
#$c.perl.say; | |
#for ^1000000 { 'a' collate 'b' } | |
say now - INIT now; | |
} | |
test-it; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment