LanguageNameSearch.php: Minor cleanup
Change-Id: If031c59fee64ad6e51dedd3328aec7eca6ed0019
This commit is contained in:
@@ -63,13 +63,10 @@ class LanguageNameSearch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$index = self::getIndex( $searchKey );
|
$index = self::getIndex( $searchKey );
|
||||||
$bucketsForIndex = [];
|
$bucketsForIndex = LanguageNameSearchData::$buckets[$index] ?? [];
|
||||||
if ( isset( LanguageNameSearchData::$buckets[$index] ) ) {
|
|
||||||
$bucketsForIndex = LanguageNameSearchData::$buckets[$index];
|
|
||||||
}
|
|
||||||
|
|
||||||
// types are 'prefix', 'infix' (in this order!)
|
// types are 'prefix', 'infix' (in this order!)
|
||||||
foreach ( $bucketsForIndex as $bucketType => $bucket ) {
|
foreach ( $bucketsForIndex as $bucket ) {
|
||||||
foreach ( $bucket as $name => $code ) {
|
foreach ( $bucket as $name => $code ) {
|
||||||
// We can skip checking languages we already have in the list
|
// We can skip checking languages we already have in the list
|
||||||
if ( isset( $results[ $code ] ) ) {
|
if ( isset( $results[ $code ] ) ) {
|
||||||
@@ -119,10 +116,10 @@ class LanguageNameSearch {
|
|||||||
if ( $codepoint < 4000 ) {
|
if ( $codepoint < 4000 ) {
|
||||||
// For latin etc. we need smaller buckets for speed
|
// For latin etc. we need smaller buckets for speed
|
||||||
return $codepoint;
|
return $codepoint;
|
||||||
} else {
|
|
||||||
// Try to group names of same script together
|
|
||||||
return $codepoint - ( $codepoint % 1000 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to group names of same script together
|
||||||
|
return $codepoint - ( $codepoint % 1000 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -143,27 +140,27 @@ class LanguageNameSearch {
|
|||||||
$number = $thisValue;
|
$number = $thisValue;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
} else {
|
}
|
||||||
// Codepoints larger than 127 are represented by multi-byte sequences
|
|
||||||
if ( $values === [] ) {
|
// Codepoints larger than 127 are represented by multi-byte sequences
|
||||||
// 224 is the lowest non-overlong-encoded codepoint.
|
if ( $values === [] ) {
|
||||||
$lookingFor = ( $thisValue < 224 ) ? 2 : 3;
|
// 224 is the lowest non-overlong-encoded codepoint.
|
||||||
|
$lookingFor = ( $thisValue < 224 ) ? 2 : 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
$values[] = $thisValue;
|
||||||
|
if ( count( $values ) === $lookingFor ) {
|
||||||
|
// Refer http://en.wikipedia.org/wiki/UTF-8#Description
|
||||||
|
if ( $lookingFor === 3 ) {
|
||||||
|
$number = ( $values[0] % 16 ) * 4096;
|
||||||
|
$number += ( $values[1] % 64 ) * 64;
|
||||||
|
$number += $values[2] % 64;
|
||||||
|
} else {
|
||||||
|
$number = ( $values[0] % 32 ) * 64;
|
||||||
|
$number += $values[1] % 64;
|
||||||
}
|
}
|
||||||
|
|
||||||
$values[] = $thisValue;
|
break;
|
||||||
if ( count( $values ) === $lookingFor ) {
|
|
||||||
// Refer http://en.wikipedia.org/wiki/UTF-8#Description
|
|
||||||
if ( $lookingFor === 3 ) {
|
|
||||||
$number = ( $values[0] % 16 ) * 4096;
|
|
||||||
$number += ( $values[1] % 64 ) * 64;
|
|
||||||
$number += $values[2] % 64;
|
|
||||||
} else {
|
|
||||||
$number = ( $values[0] % 32 ) * 64;
|
|
||||||
$number += $values[1] % 64;
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user