Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions lib/TextLanguageDetect/TextLanguageDetect.php
Original file line number Diff line number Diff line change
Expand Up @@ -1022,23 +1022,35 @@ protected function _unicode_block_name($unicode, $blocks, $block_count = -1)
$low = 1; // start with 1 because ascii was 0

// your average binary search algorithm
while ($low <= $high) {
$mid = floor(($low + $high) / 2);

if ($unicode < $blocks[$mid][0]) {
// if it's lower than the lower bound
$high = $mid - 1;

} elseif ($unicode > $blocks[$mid][1]) {
// if it's higher than the upper bound
$low = $mid + 1;

} else {
// found it
return $blocks[$mid];
if (version_compare(phpversion(), '7.0.0', '<')) {
while ($low <= $high) {
$mid = floor(($low + $high) / 2);
if ($unicode < $blocks[$mid][0]) {
// if it's lower than the lower bound
$high = $mid - 1;
} elseif ($unicode > $blocks[$mid][1]) {
// if it's higher than the upper bound
$low = $mid + 1;
} else {
// found it
return $blocks[$mid];
}
}
} else {
while ($low <= $high) {
$mid = floor(($low + $high) / 2);
if ($unicode < hexdec($blocks[$mid][0])) {
// if it's lower than the lower bound
$high = $mid - 1;
} elseif ($unicode > hexdec($blocks[$mid][1])) {
// if it's higher than the upper bound
$low = $mid + 1;
} else {
// found it
return $blocks[$mid];
}
}
}

// failed to find the block
return -1;

Expand Down