Skip to content

Commit

Permalink
defaut -> symbol
Browse files Browse the repository at this point in the history
  • Loading branch information
overtrue committed Jul 24, 2022
1 parent 8126ab9 commit 4ee638c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ composer require overtrue/pinyin:^5.0

除了获取首字母的方法外,所有方法都支持第二个参数,用于指定拼音的格式,可选值为:

- `default` 默认格式,例如 `pīn yīn`
- `symbol` (默认)声调符号,例如 `pīn yīn`
- `none` 不输出拼音,例如 `pin yin`
- `number` 末尾数字模式的拼音,例如 `pin1 yin1`

Expand Down
6 changes: 3 additions & 3 deletions src/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Converter
private const CHARS_PATH = __DIR__.'/../data/chars.php';
private const SURNAMES_PATH = __DIR__.'/../data/surnames.php';

public const TONE_STYLE_DEFAULT = 'default';
public const TONE_STYLE_SYMBOL = 'symbol';
public const TONE_STYLE_NUMBER = 'number';
public const TONE_STYLE_NONE = 'none';

Expand All @@ -18,7 +18,7 @@ class Converter
protected bool $noWords = false;

protected string $yuTo = 'yu';
protected string $toneStyle = self::TONE_STYLE_DEFAULT;
protected string $toneStyle = self::TONE_STYLE_SYMBOL;

protected array $regexps = [
'separator' => '\p{Z}',
Expand Down Expand Up @@ -230,7 +230,7 @@ protected function formatTone(string $pinyin, string $style): string
if (\str_contains($pinyin, $unicode)) {
$umlaut = $replacement[0];

if ($umlaut !== 'yu' && $style === self::TONE_STYLE_DEFAULT) {
if ($umlaut !== 'yu' && $style === self::TONE_STYLE_SYMBOL) {
continue;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Pinyin.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@
* @method static Converter useNumberTone()
* @method static Converter yuToV()
* @method static Converter yuToU()
* @method static Converter withToneStyle(string $toneStyle = 'default')
* @method static Converter withToneStyle(string $toneStyle = 'symbol')
* @method static Collection convert(string $string, callable $beforeSplit = null)
*/
class Pinyin
{
public static function name(string $name, string $toneStyle = Converter::TONE_STYLE_DEFAULT): Collection
public static function name(string $name, string $toneStyle = Converter::TONE_STYLE_SYMBOL): Collection
{
return self::surname()->withToneStyle($toneStyle)->convert($name);
}

public static function phrase(string $string, string $toneStyle = Converter::TONE_STYLE_DEFAULT): Collection
public static function phrase(string $string, string $toneStyle = Converter::TONE_STYLE_SYMBOL): Collection
{
return self::noPunctuation()->withToneStyle($toneStyle)->convert($string);
}

public static function sentence(string $string, string $toneStyle = Converter::TONE_STYLE_DEFAULT): Collection
public static function sentence(string $string, string $toneStyle = Converter::TONE_STYLE_SYMBOL): Collection
{
return self::withToneStyle($toneStyle)->convert($string);
}

public static function polyphones(string $string, string $toneStyle = Converter::TONE_STYLE_DEFAULT): Collection
public static function polyphones(string $string, string $toneStyle = Converter::TONE_STYLE_SYMBOL): Collection
{
return self::polyphonic()->withToneStyle($toneStyle)->convert($string);
}

public static function chars(string $string, string $toneStyle = Converter::TONE_STYLE_DEFAULT): Collection
public static function chars(string $string, string $toneStyle = Converter::TONE_STYLE_SYMBOL): Collection
{
return self::onlyHans()->noWords()->withToneStyle($toneStyle)->convert($string);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function test_tone_style()
$this->assertPinyin('chong qing', Converter::make()->noTone()->convert('重庆'));
$this->assertPinyin('chong2 qing4', Converter::make()->useNumberTone()->convert('重庆'));

$this->assertPinyin('chóng qìng', Converter::make()->withToneStyle(Converter::TONE_STYLE_DEFAULT)->convert('重庆'));
$this->assertPinyin('chóng qìng', Converter::make()->withToneStyle(Converter::TONE_STYLE_SYMBOL)->convert('重庆'));
$this->assertPinyin('chong qing', Converter::make()->withToneStyle(Converter::TONE_STYLE_NONE)->convert('重庆'));
$this->assertPinyin('chong2 qing4', Converter::make()->withToneStyle(Converter::TONE_STYLE_NUMBER)->convert('重庆'));
}
Expand Down

0 comments on commit 4ee638c

Please sign in to comment.