Skip to content

Commit

Permalink
bugfix overtrue#9
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Nov 27, 2014
1 parent c2c2ad4 commit 9474ece
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 4 additions & 5 deletions src/Pinyin/Pinyin.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,12 @@ public static function parse($string, array $settings = array())
$string = $instance->justChinese($string);
}

$pinyin = $instance->string2pinyin($string);

$source = $instance->string2pinyin($string);
// add accents
if ($settings['accent']) {
$pinyin = $instance->addAccents($pinyin);
$pinyin = $instance->addAccents($source);
} else {
$pinyin = $instance->removeTone($pinyin);
$pinyin = $instance->removeTone($source);
}

//add delimiter
Expand All @@ -173,7 +172,7 @@ public static function parse($string, array $settings = array())
$return = array(
'src' => $string,
'pinyin' => $instance->escape($delimitedPinyin),
'letter' => $instance->getFirstLetters($pinyin, $settings),
'letter' => $instance->getFirstLetters($source, $settings),
);

return $return;
Expand Down
9 changes: 7 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
<?php

//include __DIR__ . '/../vendor/autoload.php';
include __DIR__ . '/../src/Pinyin/Pinyin.php';

if (gethostname() == 'overtrue') {
include __DIR__ . '/../src/Pinyin/Pinyin.php';
} else {
include __DIR__ . '/../vendor/autoload.php';
}

use Overtrue\Pinyin\Pinyin;

Expand Down Expand Up @@ -40,6 +44,7 @@ public function testLetters()
$this->assertEquals('z y', Pinyin::letter('重要'));
$this->assertEquals('nh', Pinyin::letter('您好', array('delimiter' => '')));
$this->assertEquals('kxll', Pinyin::letter('康熙来了', array('delimiter' => '')));
$this->assertEquals('A B Z Z Q Z Z Z Z', Pinyin::letter("阿坝藏族羌族自治州", array('uppercase' => true)));
$this->assertEquals('d z x w q l x b d d z d g m h', Pinyin::letter('带着希望去旅行,比到达终点更美好'));
$this->assertEquals('z q s l z w z w', Pinyin::letter('赵钱孙李 周吴郑王'));
}
Expand Down

0 comments on commit 9474ece

Please sign in to comment.