Skip to content

Commit

Permalink
Fixed #175
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Jul 19, 2021
1 parent 10581b7 commit 04bdb4d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/FileDictLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct($path)
public function map(Closure $callback)
{
for ($i = 0; $i < 100; ++$i) {
$segment = $this->path.'/'.sprintf($this->segmentName, $i);
$segment = $this->path . '/' . sprintf($this->segmentName, $i);

if (file_exists($segment)) {
$dictionary = (array) include $segment;
Expand All @@ -63,7 +63,7 @@ public function map(Closure $callback)
*/
public function mapSurname(Closure $callback)
{
$surnames = $this->path.'/surnames';
$surnames = $this->path . '/surnames';

if (file_exists($surnames)) {
$dictionary = (array) include $surnames;
Expand Down
4 changes: 2 additions & 2 deletions src/GeneratorFileDictLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function __construct($path)
$this->path = $path;

for ($i = 0; $i < 100; ++$i) {
$segment = $this->path.'/'.sprintf($this->segmentName, $i);
$segment = $this->path . '/' . sprintf($this->segmentName, $i);

if (file_exists($segment) && is_file($segment)) {
array_push(static::$handles, $this->openFile($segment));
Expand Down Expand Up @@ -134,7 +134,7 @@ public function map(Closure $callback)
public function mapSurname(Closure $callback)
{
if (!static::$surnamesHandle instanceof SplFileObject) {
static::$surnamesHandle = $this->openFile($this->path.'/surnames');
static::$surnamesHandle = $this->openFile($this->path . '/surnames');
}

$this->traversing($this->getGenerator([static::$surnamesHandle]), $callback);
Expand Down
4 changes: 2 additions & 2 deletions src/MemoryFileDictLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function __construct($path)
$this->path = $path;

for ($i = 0; $i < 100; ++$i) {
$segment = $path.'/'.sprintf($this->segmentName, $i);
$segment = $path . '/' . sprintf($this->segmentName, $i);

if (file_exists($segment)) {
$this->segments[] = (array) include $segment;
Expand Down Expand Up @@ -81,7 +81,7 @@ public function map(Closure $callback)
public function mapSurname(Closure $callback)
{
if (empty($this->surnames)) {
$surnames = $this->path.'/surnames';
$surnames = $this->path . '/surnames';

if (file_exists($surnames)) {
$this->surnames = (array) include $surnames;
Expand Down
8 changes: 4 additions & 4 deletions src/Pinyin.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public function setLoader(DictLoaderInterface $loader)
public function getLoader()
{
if (!($this->loader instanceof DictLoaderInterface)) {
$dataDir = dirname(__DIR__).'/data/';
$dataDir = dirname(__DIR__) . '/data/';

$loaderName = $this->loader;
$this->loader = new $loaderName($dataDir);
Expand Down Expand Up @@ -229,7 +229,7 @@ protected function convertSurname($string, $dictLoader)
$dictLoader->mapSurname(function ($dictionary) use (&$string) {
foreach ($dictionary as $surname => $pinyin) {
if (0 === strpos($string, $surname)) {
$string = $pinyin.mb_substr($string, mb_strlen($surname, 'UTF-8'), mb_strlen($string, 'UTF-8') - 1, 'UTF-8');
$string = $pinyin . mb_substr($string, mb_strlen($surname, 'UTF-8'), mb_strlen($string, 'UTF-8') - 1, 'UTF-8');

break;
}
Expand Down Expand Up @@ -282,7 +282,7 @@ public function hasOption($option, $check)
protected function prepare($string, $option = \PINYIN_DEFAULT)
{
$string = preg_replace_callback('~[a-z0-9_-]+~i', function ($matches) {
return "\t".$matches[0];
return "\t" . $matches[0];
}, $string);

$regex = ['\p{Han}', '\p{Z}', '\p{M}', "\t"];
Expand Down Expand Up @@ -332,7 +332,7 @@ protected function formatTone($pinyin, $option = \PINYIN_NO_TONE)
$umlaut = 'v';
}

$pinyin = str_replace($unicode, $umlaut, $pinyin).($this->hasOption($option, PINYIN_ASCII_TONE) ? $replacement[1] : '');
$pinyin = str_replace($unicode, $umlaut, $pinyin) . ($this->hasOption($option, PINYIN_ASCII_TONE) ? $replacement[1] : '');
}
}

Expand Down

0 comments on commit 04bdb4d

Please sign in to comment.