/**
  * @covers ArrayUtils::findLowerBound
  * @dataProvider provideFindLowerBound
  */
 function testFindLowerBound($valueCallback, $valueCount, $comparisonCallback, $target, $expected)
 {
     $this->assertSame(ArrayUtils::findLowerBound($valueCallback, $valueCount, $comparisonCallback, $target), $expected);
 }
Exemple #2
0
 public function getFirstLetter($string)
 {
     $string = strval($string);
     if ($string === '') {
         return '';
     }
     $firstChar = mb_substr($string, 0, 1, 'UTF-8');
     // If the first character is a CJK character, just return that character.
     if (ord($firstChar) > 0x7f && self::isCjk(UtfNormal\Utils::utf8ToCodepoint($firstChar))) {
         return $firstChar;
     }
     $sortKey = $this->getPrimarySortKey($string);
     // Do a binary search to find the correct letter to sort under
     $min = ArrayUtils::findLowerBound([$this, 'getSortKeyByLetterIndex'], $this->getFirstLetterCount(), 'strcmp', $sortKey);
     if ($min === false) {
         // Before the first letter
         return '';
     }
     $sortLetter = $this->getLetterByIndex($min);
     if ($this->useNumericCollation) {
         // If the sort letter is a number, return '0–9' (or localized equivalent).
         // ASCII value of 0 is 48. ASCII value of 9 is 57.
         // Note that this also applies to non-Arabic numerals since they are
         // mapped to Arabic numeral sort letters. For example, ২ sorts as 2.
         if (ord($sortLetter) >= 48 && ord($sortLetter) <= 57) {
             $sortLetter = wfMessage('category-header-numerals')->numParams(0, 9)->text();
         }
     }
     return $sortLetter;
 }
Exemple #3
0
 function getFirstLetter($string)
 {
     $string = strval($string);
     if ($string === '') {
         return '';
     }
     // Check for CJK
     $firstChar = mb_substr($string, 0, 1, 'UTF-8');
     if (ord($firstChar) > 0x7f && self::isCjk(UtfNormal\Utils::utf8ToCodepoint($firstChar))) {
         return $firstChar;
     }
     $sortKey = $this->getPrimarySortKey($string);
     // Do a binary search to find the correct letter to sort under
     $min = ArrayUtils::findLowerBound(array($this, 'getSortKeyByLetterIndex'), $this->getFirstLetterCount(), 'strcmp', $sortKey);
     if ($min === false) {
         // Before the first letter
         return '';
     }
     return $this->getLetterByIndex($min);
 }
Exemple #4
0
 /**
  * Do a binary search, and return the index of the largest item that sorts
  * less than or equal to the target value.
  *
  * @deprecated in 1.23; use ArrayUtils::findLowerBound() instead
  *
  * @param array $valueCallback A function to call to get the value with
  *     a given array index.
  * @param int $valueCount The number of items accessible via $valueCallback,
  *     indexed from 0 to $valueCount - 1
  * @param array $comparisonCallback A callback to compare two values, returning
  *     -1, 0 or 1 in the style of strcmp().
  * @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.
  */
 function findLowerBound($valueCallback, $valueCount, $comparisonCallback, $target)
 {
     wfDeprecated(__METHOD__, '1.23');
     return ArrayUtils::findLowerBound($valueCallback, $valueCount, $comparisonCallback, $target);
 }