Skip to content

Commit 9b576d5

Browse files
committed
:octocat: Kanji, Hanzi: do not mess with mb_detect_order(), feed the expected encodings directly into mb_detect_encoding()
(cherry picked from commit 3a610d2)
1 parent dc193b8 commit 9b576d5

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/Data/Hanzi.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use chillerlan\QRCode\Common\{BitBuffer, Mode};
1414
use Throwable;
1515
use function chr, implode, intdiv, is_string, mb_convert_encoding, mb_detect_encoding,
16-
mb_detect_order, mb_internal_encoding, mb_strlen, ord, sprintf, strlen;
16+
mb_internal_encoding, mb_strlen, ord, sprintf, strlen;
1717

1818
/**
1919
* Hanzi (simplified Chinese) mode, GBT18284-2000: 13-bit double-byte characters from the GB2312/GB18030 character set
@@ -67,9 +67,12 @@ public function getLengthInBits():int{
6767
* @throws \chillerlan\QRCode\Data\QRCodeDataException
6868
*/
6969
public static function convertEncoding(string $string):string{
70-
mb_detect_order([mb_internal_encoding(), 'UTF-8', 'GB2312', 'GB18030', 'CP936', 'EUC-CN', 'HZ']);
7170

72-
$detected = mb_detect_encoding($string, null, true);
71+
$detected = mb_detect_encoding(
72+
$string,
73+
[mb_internal_encoding(), 'UTF-8', 'GB2312', 'GB18030', 'CP936', 'EUC-CN', 'HZ'],
74+
true,
75+
);
7376

7477
if($detected === false){
7578
throw new QRCodeDataException('mb_detect_encoding error');

src/Data/Kanji.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use chillerlan\QRCode\Common\{BitBuffer, Mode};
1414
use Throwable;
1515
use function chr, implode, intdiv, is_string, mb_convert_encoding, mb_detect_encoding,
16-
mb_detect_order, mb_internal_encoding, mb_strlen, ord, sprintf, strlen;
16+
mb_internal_encoding, mb_strlen, ord, sprintf, strlen;
1717

1818
/**
1919
* Kanji mode: 13-bit double-byte characters from the Shift-JIS character set
@@ -60,9 +60,7 @@ public function getLengthInBits():int{
6060
* @throws \chillerlan\QRCode\Data\QRCodeDataException
6161
*/
6262
public static function convertEncoding(string $string):string{
63-
mb_detect_order([mb_internal_encoding(), 'UTF-8', 'SJIS', 'SJIS-2004']);
64-
65-
$detected = mb_detect_encoding($string, null, true);
63+
$detected = mb_detect_encoding($string, [mb_internal_encoding(), 'UTF-8', 'SJIS', 'SJIS-2004'], true);
6664

6765
if($detected === false){
6866
throw new QRCodeDataException('mb_detect_encoding error');

0 commit comments

Comments
 (0)