Struct pinyin_parser::PinyinParser
source · pub struct PinyinParser { /* private fields */ }
Implementations§
source§impl PinyinParser
impl PinyinParser
pub const fn new() -> Self
pub const fn is_strict(self, b: bool) -> Self
👎Deprecated: Use
with_strictness(Strictness::Strict)
or with_strictness(Strictness::Loose)
pub const fn with_strictness(self, strictness: Strictness) -> Self
pub const fn preserve_spaces(self, b: bool) -> Self
pub const fn preserve_punctuations(self, b: bool) -> Self
sourcepub const fn preserve_miscellaneous(self, b: bool) -> Self
pub const fn preserve_miscellaneous(self, b: bool) -> Self
use pinyin_parser::PinyinParser;
let parser = PinyinParser::new()
.is_strict(true)
.preserve_miscellaneous(true);
assert_eq!(
parser
.parse("你Nǐ 好hǎo")
.into_iter()
.collect::<Vec<_>>(),
vec!["你", "nǐ", "好", "hǎo"]
)
sourcepub fn parse(self, s: &str) -> PinyinParserIter ⓘ
pub fn parse(self, s: &str) -> PinyinParserIter ⓘ
use pinyin_parser::PinyinParser;
let parser = PinyinParser::new()
.is_strict(true)
.preserve_punctuations(true)
.preserve_spaces(true);
assert_eq!(
parser
.parse("Nǐ zuò shénme?")
.into_iter()
.collect::<Vec<_>>(),
vec!["nǐ", " ", "zuò", " ", "shén", "me", "?"]
)
sourcepub fn strict(s: &str) -> PinyinParserIter ⓘ
pub fn strict(s: &str) -> PinyinParserIter ⓘ
Strict mode:
- forbids the use of breve instead of hacek to represent the third tone
- forbids the use of IPA
ɡ
(U+0261) instead ofg
, and other such lookalike characters - allows apostrophes only before an
a
, ane
or ano
use pinyin_parser::PinyinParser;
assert_eq!(
PinyinParser::strict("jīntiān")
.into_iter()
.collect::<Vec<_>>(),
vec!["jīn", "tiān"]
);
ⓘ
use pinyin_parser::PinyinParser;
assert_eq!(
PinyinParser::strict("zǒnɡshì") // this `ɡ` is not the `g` from ASCII
.into_iter()
.collect::<Vec<_>>(),
vec!["zǒng", "shì"]
);
ⓘ
use pinyin_parser::PinyinParser;
assert_eq!(
// An apostrophe can come only before an `a`, an `e` or an `o` in strict mode
PinyinParser::strict("Yīng'guó")
.into_iter()
.collect::<Vec<_>>(),
vec!["yīng", "guó"]
);
This parser supports the use of ẑ
, ĉ
, ŝ
and ŋ
, though I have never seen anyone use it.
use pinyin_parser::PinyinParser;
assert_eq!(
PinyinParser::strict("Ẑāŋ").into_iter().collect::<Vec<_>>(),
vec!["zhāng"]
)
sourcepub fn loose(s: &str) -> PinyinParserIter ⓘ
pub fn loose(s: &str) -> PinyinParserIter ⓘ
use pinyin_parser::PinyinParser;
assert_eq!(
// 'ă' is LATIN SMALL LETTER A WITH BREVE and is not accepted in strict mode.
// The correct alphabet to use is 'ǎ'.
PinyinParser::loose("mián'ăo")
.into_iter()
.collect::<Vec<_>>(),
vec!["mián", "ǎo"]
);
use pinyin_parser::PinyinParser;
assert_eq!(
// An apostrophe can come only before an `a`, an `e` or an `o` in strict mode,
// but allowed here because it's loose
PinyinParser::loose("Yīng'guó")
.into_iter()
.collect::<Vec<_>>(),
vec!["yīng", "guó"]
);
Trait Implementations§
source§impl Clone for PinyinParser
impl Clone for PinyinParser
source§fn clone(&self) -> PinyinParser
fn clone(&self) -> PinyinParser
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for PinyinParser
impl Debug for PinyinParser
source§impl Default for PinyinParser
impl Default for PinyinParser
source§impl Hash for PinyinParser
impl Hash for PinyinParser
source§impl PartialEq for PinyinParser
impl PartialEq for PinyinParser
source§fn eq(&self, other: &PinyinParser) -> bool
fn eq(&self, other: &PinyinParser) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.impl Copy for PinyinParser
impl Eq for PinyinParser
impl StructuralEq for PinyinParser
impl StructuralPartialEq for PinyinParser
Auto Trait Implementations§
impl RefUnwindSafe for PinyinParser
impl Send for PinyinParser
impl Sync for PinyinParser
impl Unpin for PinyinParser
impl UnwindSafe for PinyinParser
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more