From 7da9756a17e981cfc385d8a6e92deb3a28af944d Mon Sep 17 00:00:00 2001 From: tarastalian Date: Wed, 23 Nov 2016 11:56:33 +0100 Subject: [PATCH 1/2] Update TextLanguageDetect.php Convert the hex block into dec to make proper compare with the character's unicode in PHP7 --- lib/TextLanguageDetect/TextLanguageDetect.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/TextLanguageDetect/TextLanguageDetect.php b/lib/TextLanguageDetect/TextLanguageDetect.php index 61dd64b..f0d17dd 100755 --- a/lib/TextLanguageDetect/TextLanguageDetect.php +++ b/lib/TextLanguageDetect/TextLanguageDetect.php @@ -1025,14 +1025,12 @@ protected function _unicode_block_name($unicode, $blocks, $block_count = -1) while ($low <= $high) { $mid = floor(($low + $high) / 2); - if ($unicode < $blocks[$mid][0]) { + if ($unicode < hexdec($blocks[$mid][0])) { // if it's lower than the lower bound $high = $mid - 1; - - } elseif ($unicode > $blocks[$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]; From 1df5bc5739888b6062268d6476525c639345da20 Mon Sep 17 00:00:00 2001 From: tarastalian Date: Wed, 17 May 2017 10:07:08 +0200 Subject: [PATCH 2/2] Update TextLanguageDetect.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AƱado la posibilidad de que funcione tanto para PHP7 como para versiones anteriores --- lib/TextLanguageDetect/TextLanguageDetect.php | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/lib/TextLanguageDetect/TextLanguageDetect.php b/lib/TextLanguageDetect/TextLanguageDetect.php index f0d17dd..2a55bb3 100755 --- a/lib/TextLanguageDetect/TextLanguageDetect.php +++ b/lib/TextLanguageDetect/TextLanguageDetect.php @@ -1022,21 +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 < 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]; + 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;