Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mozillazg/rust-pinyin
汉字转拼音
https://github.com/mozillazg/rust-pinyin
chinese hanzi hanzi-pinyin pinyin rust
Last synced: about 1 month ago
JSON representation
汉字转拼音
- Host: GitHub
- URL: https://github.com/mozillazg/rust-pinyin
- Owner: mozillazg
- License: mit
- Created: 2015-05-30T03:26:12.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-05-23T14:36:03.000Z (over 1 year ago)
- Last Synced: 2024-09-14T12:26:02.825Z (about 2 months ago)
- Topics: chinese, hanzi, hanzi-pinyin, pinyin, rust
- Language: Rust
- Homepage: https://docs.rs/pinyin/
- Size: 4.82 MB
- Stars: 199
- Watchers: 8
- Forks: 24
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# rust-pinyin
[![Build Status](https://github.com/mozillazg/rust-pinyin/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/mozillazg/rust-pinyin/actions/workflows/ci.yml)
[![Crates.io Version](https://img.shields.io/crates/v/pinyin.svg)](https://crates.io/crates/pinyin)
[![Doc](https://img.shields.io/badge/doc-reference-blue.svg)](https://docs.rs/pinyin/)汉语拼音转换工具 Rust 版
Installation
------------Add this to your `Cargo.toml`:
```
[dependencies]
pinyin = "0.10"
```Documentation
--------------API documentation can be found here: https://docs.rs/pinyin/
Usage
------```rust
use pinyin::{ToPinyin, ToPinyinMulti};fn main() {
let hans = "中国人";// 无声调,输出 zhong guo ren
for pinyin in hans.to_pinyin() {
if let Some(pinyin) = pinyin {
print!("{} ", pinyin.plain());
}
}
println!();// 包含声调,输出 zhōng guó rén
for pinyin in hans.to_pinyin() {
if let Some(pinyin) = pinyin {
print!("{} ", pinyin.with_tone());
}
}
println!();// 声调用数字表示,输出 zho1ng guo2 re2n
for pinyin in hans.to_pinyin() {
if let Some(pinyin) = pinyin {
print!("{} ", pinyin.with_tone_num());
}
}
println!();// 多音字,输出
// zho1ng zho4ng
// guo2
// re2n
for multi in hans.to_pinyin_multi() {
if let Some(multi) = multi {
for pinyin in multi {
print!("{} ", pinyin.with_tone_num());
}
println!();
}
}
}
```Build
------------```
$ cargo build
```Test
------------```
$ cargo test
```Data
-----使用来自 [pinyin-data](https://github.com/mozillazg/pinyin-data) 的拼音数据。
Related Projects
-----------------* [hotoo/pinyin](https://github.com/hotoo/pinyin): 汉语拼音转换工具 Node.js/JavaScript 版。
* [mozillazg/python-pinyin](https://github.com/mozillazg/python-pinyin): 汉语拼音转换工具 Python 版。
* [mozillazg/go-pinyin](https://github.com/mozillazg/go-pinyin): 汉语拼音转换工具 Go 版。