pub struct PinyinParser { /* private fields */ }

Implementations§

source§

impl PinyinParser

source

pub const fn new() -> Self

source

pub const fn is_strict(self, b: bool) -> Self

👎Deprecated: Use with_strictness(Strictness::Strict) or with_strictness(Strictness::Loose)
source

pub const fn with_strictness(self, strictness: Strictness) -> Self

source

pub const fn preserve_spaces(self, b: bool) -> Self

source

pub const fn preserve_punctuations(self, b: bool) -> Self

source

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"]
)
source

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", "?"]
)
source

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 of g, and other such lookalike characters
  • allows apostrophes only before an a, an e or an o
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"]
)
source

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

source§

fn clone(&self) -> PinyinParser

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PinyinParser

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for PinyinParser

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Hash for PinyinParser

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for PinyinParser

source§

fn eq(&self, other: &PinyinParser) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Copy for PinyinParser

source§

impl Eq for PinyinParser

source§

impl StructuralEq for PinyinParser

source§

impl StructuralPartialEq for PinyinParser

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.