-
Notifications
You must be signed in to change notification settings - Fork 58
Open
Description
tone_index 1 2 3 4 分别是 4 个声,5 是什么?而且有 91 个有 5.
如果 tone_index 是 5 的话,下面代码就会出错
tone_index = pinyin[-1].to_i
pinyin = pinyin[0...-1]
%w(a o e i u v).each { |v|
break if pinyin.tr! v, TONE_MARK[v.to_sym][tone_index]
}代码来自 (https://github.com/flyerhzm/chinese_pinyin/blob/master/lib/chinese_pinyin.rb#L86-L90)
因为每个 TONE_MARK[v.to_sym] 都只有 5 个元素,因此会取到 nil,再进行 tr! 就会报错。
有些字的第一个拼音的 tone 不是 5,所以不会出问题。但也有不少字的第一个拼音的 tone 是 5,
awk '$2~/5/{print $1,$2}' data/pinyin-utf8.dat
㟷 da5
了 le5
们 men5
們 men5
吗 ma5
吧 ba5
吶 ne5
呗 bei5
哟 yo5这些字转成拼音都会报错.
Pinyin.t('呗', tonemarks: true)
# : in `tr!': no implicit conversion of nil into String (TypeError)Metadata
Metadata
Assignees
Labels
No labels