Skip to content

Commit 3a610d2

Browse files
committed
:octocat: Kanji, Hanzi: do not mess with mb_detect_order(), feed the expected encodings directly into mb_detect_encoding()
1 parent 01ff294 commit 3a610d2

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
@@ -14,7 +14,7 @@
1414
use chillerlan\QRCode\Common\{BitBuffer, Mode};
1515
use Throwable;
1616
use function chr, implode, intdiv, is_string, mb_convert_encoding, mb_detect_encoding,
17-
mb_detect_order, mb_internal_encoding, mb_strlen, ord, sprintf, strlen;
17+
mb_internal_encoding, mb_strlen, ord, sprintf, strlen;
1818

1919
/**
2020
* Hanzi (simplified Chinese) mode, GBT18284-2000: 13-bit double-byte characters from the GB2312/GB18030 character set
@@ -55,9 +55,12 @@ public function getLengthInBits():int{
5555
}
5656

5757
public static function convertEncoding(string $string):string{
58-
mb_detect_order([mb_internal_encoding(), 'UTF-8', 'GB2312', 'GB18030', 'CP936', 'EUC-CN', 'HZ']);
5958

60-
$detected = mb_detect_encoding($string, null, true);
59+
$detected = mb_detect_encoding(
60+
$string,
61+
[mb_internal_encoding(), 'UTF-8', 'GB2312', 'GB18030', 'CP936', 'EUC-CN', 'HZ'],
62+
true,
63+
);
6164

6265
if($detected === false){
6366
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
@@ -14,7 +14,7 @@
1414
use chillerlan\QRCode\Common\{BitBuffer, Mode};
1515
use Throwable;
1616
use function chr, implode, intdiv, is_string, mb_convert_encoding, mb_detect_encoding,
17-
mb_detect_order, mb_internal_encoding, mb_strlen, ord, sprintf, strlen;
17+
mb_internal_encoding, mb_strlen, ord, sprintf, strlen;
1818

1919
/**
2020
* Kanji mode: 13-bit double-byte characters from the Shift-JIS character set
@@ -48,9 +48,7 @@ public function getLengthInBits():int{
4848
}
4949

5050
public static function convertEncoding(string $string):string{
51-
mb_detect_order([mb_internal_encoding(), 'UTF-8', 'SJIS', 'SJIS-2004']);
52-
53-
$detected = mb_detect_encoding($string, null, true);
51+
$detected = mb_detect_encoding($string, [mb_internal_encoding(), 'UTF-8', 'SJIS', 'SJIS-2004'], true);
5452

5553
if($detected === false){
5654
throw new QRCodeDataException('mb_detect_encoding error');

0 commit comments

Comments
 (0)