gnuish / pinyin-zhuyin

Convert between pinyin forms and zhuyin
MIT License
3 stars 1 forks source link

Conversion returns `None` for some input #1

Open PSeitz opened 1 year ago

PSeitz commented 1 year ago
use pinyin_zhuyin::pinyin_to_zhuyin;

fn main() {
    dbg!(pinyin_to_zhuyin(&"yi1 tuan2")); // --> None
    dbg!(pinyin_to_zhuyin(&"yi1tuan2"));// --> None
    dbg!(pinyin_to_zhuyin(&"yī tuán")); // --> None
    dbg!(pinyin_to_zhuyin(&"yītuán")); // --> None
}
gnuish commented 1 year ago

Hi, thank you for the issue 🙂 the API is currently for single words/syllables, so for multiple you will have to separate them first.

E.g. for using whitespace as your delimiter:

let zhuyin: Vec<String> = my_string
    .split_whitespace()
    .map(|s| pinyin_to_zhuyin(s)?)
    .collect();

Perhaps a function can be added for converting multiple words within a given string, whether there is whitespace or not, e.g. "wo3 ai4 pin1yin1".