Skip to content

Commit

Permalink
Correction PHP8 : Array and string offset access syntax with curly br…
Browse files Browse the repository at this point in the history
…aces is no longer supported
  • Loading branch information
esimler committed Oct 6, 2021
1 parent 11a3520 commit 1f77455
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions lib/TextLanguageDetect/TextLanguageDetect.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private function _configure($config)
*/
public function _get_data_loc($fname)
{
if ($fname{0} == '/' || $fname{0} == '.') {
if ($fname[0] == '/' || $fname[0] == '.') {
// if filename starts with a slash, assume it's an absolute pathname
// and skip whatever is in $this->_data_dir
return $fname;
Expand Down Expand Up @@ -1522,31 +1522,31 @@ protected function _utf8char2unicode($char)
case 1:
// normal ASCII-7 byte
// 0xxxxxxx --> 0xxxxxxx
return ord($char{0});
return ord($char[0]);

case 2:
// 2 byte unicode
// 110zzzzx 10xxxxxx --> 00000zzz zxxxxxxx
$z = (ord($char{0}) & 0x000001F) << 6;
$x = (ord($char{1}) & 0x0000003F);
$z = (ord($char[0]) & 0x000001F) << 6;
$x = (ord($char[1]) & 0x0000003F);
return ($z | $x);

case 3:
// 3 byte unicode
// 1110zzzz 10zxxxxx 10xxxxxx --> zzzzzxxx xxxxxxxx
$z = (ord($char{0}) & 0x0000000F) << 12;
$x1 = (ord($char{1}) & 0x0000003F) << 6;
$x2 = (ord($char{2}) & 0x0000003F);
$z = (ord($char[0]) & 0x0000000F) << 12;
$x1 = (ord($char[1]) & 0x0000003F) << 6;
$x2 = (ord($char[2]) & 0x0000003F);
return ($z | $x1 | $x2);

case 4:
// 4 byte unicode
// 11110zzz 10zzxxxx 10xxxxxx 10xxxxxx -->
// 000zzzzz xxxxxxxx xxxxxxxx
$z1 = (ord($char{0}) & 0x00000007) << 18;
$z2 = (ord($char{1}) & 0x0000003F) << 12;
$x1 = (ord($char{2}) & 0x0000003F) << 6;
$x2 = (ord($char{3}) & 0x0000003F);
$z1 = (ord($char[0]) & 0x00000007) << 18;
$z2 = (ord($char[1]) & 0x0000003F) << 12;
$x1 = (ord($char[2]) & 0x0000003F) << 6;
$x2 = (ord($char[3]) & 0x0000003F);
return ($z1 | $z2 | $x1 | $x2);
}
}
Expand All @@ -1567,7 +1567,7 @@ protected function _utf8char2unicode($char)
*/
static function _next_char($str, &$counter, $special_convert = false)
{
$char = $str{$counter++};
$char = $str[$counter++];
$ord = ord($char);

// for a description of the utf8 system see
Expand All @@ -1591,7 +1591,7 @@ static function _next_char($str, &$counter, $special_convert = false)

} elseif ($ord >> 5 == 6) { // two-byte char
// multi-byte chars
$nextchar = $str{$counter++}; // get next byte
$nextchar = $str[$counter++]; // get next byte

// lower-casing of non-ascii characters is still incomplete

Expand Down Expand Up @@ -1633,12 +1633,12 @@ static function _next_char($str, &$counter, $special_convert = false)
} elseif ($ord >> 4 == 14) { // three-byte char

// tag on next 2 bytes
return $char . $str{$counter++} . $str{$counter++};
return $char . $str[$counter++] . $str[$counter++];

} elseif ($ord >> 3 == 30) { // four-byte char

// tag on next 3 bytes
return $char . $str{$counter++} . $str{$counter++} . $str{$counter++};
return $char . $str[$counter++] . $str[$counter++] . $str[$counter++];

} else {
// error?
Expand Down

0 comments on commit 1f77455

Please sign in to comment.