20 [
'service' =>
'icu-collation' ] );
21 $this->locale = $locale;
34 private static function encode( $strings ) {
36 foreach ( $strings as $s ) {
37 $ret .= sprintf(
"%08x", strlen( $s ) ) . $s;
48 private static function decode(
$blob ) {
51 while ( $p < strlen(
$blob ) ) {
52 $len = intval( substr(
$blob, $p, 8 ), 16 );
54 $ret[] = substr(
$blob, $p, $len );
61 if ( !count( $strings ) ) {
64 $blob = $this->rpcClient->call(
66 self::class .
'::' .
'doGetSortKeys',
69 self::encode( array_values( $strings ) )
72 'classes' => [ parent::class, self::class ],
77 array_keys( $strings ),
84 throw new RuntimeException( __METHOD__ .
': not implemented' );
95 $mainCollator = Collator::create( $locale );
96 if ( !$mainCollator ) {
97 throw new RuntimeException(
"Invalid ICU locale specified for collation: $locale" );
101 if ( str_ends_with( $locale,
'-u-kn' ) ) {
102 $mainCollator->setAttribute( Collator::NUMERIC_COLLATION, Collator::ON );
105 foreach ( self::decode(
$blob ) as $string ) {
106 $ret[] = $mainCollator->getSortKey( $string );
108 return self::encode( $ret );
An ICU collation that uses a remote server to compute sort keys.
__construct(ShellboxClientFactory $shellboxClientFactory, $locale)
static doGetSortKeys( $locale, $blob)
The remote entry point.
getSortKey( $string)
Given a string, convert it to a (hopefully short) key that can be used for efficient sorting.
getSortKeys( $strings)
Get multiple sort keys.
getFirstLetter( $string)
Given a string, return the logical "first letter" to be used for grouping on category pages and so on...