Skip to content

Commit

Permalink
修复一个multibyte字符产生的问题 (#118)
Browse files Browse the repository at this point in the history
* 修复一个multibyte字符产生的问题

* 修复一个代码风格问题
  • Loading branch information
ssynhtn authored and overtrue committed Jan 11, 2019
1 parent 6ddac33 commit 1350518
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Pinyin.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public function abbr($string, $delimiter = '', $option = PINYIN_DEFAULT)
}

return implode($delimiter, array_map(function ($pinyin) {
return \is_numeric($pinyin) ? $pinyin : $pinyin[0];
return \is_numeric($pinyin) ? $pinyin : mb_substr($pinyin, 0, 1);
}, $this->convert($string, $option)));
}

Expand Down
11 changes: 11 additions & 0 deletions tests/AbstractDictLoaderTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@

namespace Overtrue\Pinyin\Test;

use Overtrue\Pinyin\Pinyin;
use PHPUnit_Framework_TestCase;

abstract class AbstractDictLoaderTestCase extends PHPUnit_Framework_TestCase
{
/**
* @var Pinyin
*/
protected $pinyin;

public function testConvert()
Expand Down Expand Up @@ -111,6 +115,13 @@ public function testSpecialWords()
$this->assertEquals('zhōng dù xìng fèi shuǐ zhǒng', $pinyin->sentence('中度性肺水肿', \PINYIN_TONE));
}

// test multibyte non-Chinese character
public function testSpecialWordsUsingAbbr()
{
$pinyin = $this->pinyin;
$this->assertEquals('Ⅲdfscdzz', $pinyin->abbr('Ⅲ度房室传导阻滞', PINYIN_KEEP_ENGLISH | PINYIN_KEEP_NUMBER));
}

// test Polyphone
public function testPolyphone()
{
Expand Down

0 comments on commit 1350518

Please sign in to comment.