}
class IcuCollation extends Collation {
+ const FIRST_LETTER_VERSION = 1;
+
var $primaryCollator, $mainCollator, $locale;
var $firstLetterData;
/**
* Additional characters (or character groups) to be considered separate
- * letters for given languages, compared to the data stored in the
+ * letters for given languages, or to be removed from the list of such
+ * letters (denoted by keys starting with '-').
+ *
+ * These are additions to (or subtractions from) the data stored in the
* first-letters-root.ser file (which among others includes full basic latin,
* cyrillic and greek alphabets).
*
'sq' => array( "Ç", "Dh", "Ë", "Gj", "Ll", "Nj", "Rr", "Sh", "Th", "Xh", "Zh" ),
'sr' => array(),
'sv' => array( "Å", "Ä", "Ö" ),
+ '-sv' => array( "Þ" ), // sorted as "th" in Swedish, causing unexpected output - bug 45446
'tk' => array( "Ç", "Ä", "Ž", "Ň", "Ö", "Ş", "Ü", "Ý" ),
'tl' => array( "Ñ", "Ng" ),
'tr' => array( "Ç", "Ğ", "İ", "Ö", "Ş", "Ü" ),
$cacheKey = wfMemcKey( 'first-letters', $this->locale );
$cacheEntry = $cache->get( $cacheKey );
- if ( $cacheEntry ) {
+ if ( $cacheEntry && isset( $cacheEntry['version'] )
+ && $cacheEntry['version'] == self::FIRST_LETTER_VERSION )
+ {
$this->firstLetterData = $cacheEntry;
return $this->firstLetterData;
}
if ( isset ( self::$tailoringFirstLetters[$this->locale] ) ) {
$letters = wfGetPrecompiledData( "first-letters-root.ser" );
+ // Append additional characters
$letters = array_merge( $letters, self::$tailoringFirstLetters[$this->locale] );
+ // Remove unnecessary ones, if any
+ if ( isset( self::$tailoringFirstLetters[ '-' . $this->locale ] ) ) {
+ $letters = array_diff( $letters, self::$tailoringFirstLetters[ '-' . $this->locale ] );
+ }
} else {
$letters = wfGetPrecompiledData( "first-letters-{$this->locale}.ser" );
if ( $letters === false ) {
ksort( $letterMap, SORT_STRING );
$data = array(
'chars' => array_values( $letterMap ),
- 'keys' => array_keys( $letterMap )
+ 'keys' => array_keys( $letterMap ),
+ 'version' => self::FIRST_LETTER_VERSION,
);
// Reduce memory usage before caching
* Do a binary search, and return the index of the largest item that sorts
* less than or equal to the target value.
*
- * @param $valueCallback array A function to call to get the value with
+ * @param array $valueCallback A function to call to get the value with
* a given array index.
- * @param $valueCount int The number of items accessible via $valueCallback,
+ * @param int $valueCount The number of items accessible via $valueCallback,
* indexed from 0 to $valueCount - 1
- * @param $comparisonCallback array A callback to compare two values, returning
+ * @param array $comparisonCallback A callback to compare two values, returning
* -1, 0 or 1 in the style of strcmp().
- * @param $target string The target value to find.
+ * @param string $target The target value to find.
*
* @return int|bool The item index of the lower bound, or false if the target value
* sorts before all items.