mod functions;
mod naive;
mod number_to_chinese_error;
mod traits;
mod functions_test;
use alloc::string::String;
use functions::*;
pub use naive::*;
pub use number_to_chinese_error::*;
pub use traits::*;
use crate::{ChineseCase, ChineseCountMethod, ChineseSign, ChineseVariant};
#[inline]
pub fn from_u8_to_chinese(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: u8,
) -> String {
from_u128_to_chinese_low(chinese_variant, chinese_case, value as u128).unwrap()
}
#[inline]
pub fn from_u16_to_chinese(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: u16,
) -> String {
from_u128_to_chinese_low(chinese_variant, chinese_case, value as u128).unwrap()
}
#[inline]
pub fn from_u32_to_chinese_low(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: u32,
) -> String {
from_u128_to_chinese_low(chinese_variant, chinese_case, value as u128).unwrap()
}
#[inline]
pub fn from_u32_to_chinese_ten_thousand(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: u32,
) -> String {
from_u128_to_chinese_ten_thousand(chinese_variant, chinese_case, value as u128)
}
#[inline]
pub fn from_u32_to_chinese_middle(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: u32,
) -> String {
from_u128_to_chinese_middle(chinese_variant, chinese_case, value as u128)
}
#[inline]
pub fn from_u32_to_chinese_high(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: u32,
) -> String {
from_u128_to_chinese_high(chinese_variant, chinese_case, value as u128)
}
#[inline]
pub fn from_u64_to_chinese_low(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: u64,
) -> Result<String, NumberToChineseError> {
from_u128_to_chinese_low(chinese_variant, chinese_case, value as u128)
}
#[inline]
pub fn from_u64_to_chinese_ten_thousand(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: u64,
) -> String {
from_u128_to_chinese_ten_thousand(chinese_variant, chinese_case, value as u128)
}
#[inline]
pub fn from_u64_to_chinese_middle(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: u64,
) -> String {
from_u128_to_chinese_middle(chinese_variant, chinese_case, value as u128)
}
#[inline]
pub fn from_u64_to_chinese_high(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: u64,
) -> String {
from_u128_to_chinese_high(chinese_variant, chinese_case, value as u128)
}
#[inline]
pub fn from_u128_to_chinese_low(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: u128,
) -> Result<String, NumberToChineseError> {
if value >= 1_0000_0000_0000_0000 {
return Err(NumberToChineseError::Overflow);
}
Ok(unsigned_integer_to_chinese_low(chinese_variant, chinese_case, false, value))
}
#[inline]
pub fn from_u128_to_chinese_ten_thousand(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: u128,
) -> String {
unsigned_integer_to_chinese_ten_thousand(chinese_variant, chinese_case, false, value)
}
#[inline]
pub fn from_u128_to_chinese_middle(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: u128,
) -> String {
unsigned_integer_to_chinese_middle(chinese_variant, chinese_case, false, value)
}
#[inline]
pub fn from_u128_to_chinese_high(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: u128,
) -> String {
unsigned_integer_to_chinese_high(chinese_variant, chinese_case, false, value)
}
#[inline]
pub fn from_usize_to_chinese_low(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: usize,
) -> Result<String, NumberToChineseError> {
from_u128_to_chinese_low(chinese_variant, chinese_case, value as u128)
}
#[inline]
pub fn from_usize_to_chinese_ten_thousand(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: usize,
) -> String {
from_u128_to_chinese_ten_thousand(chinese_variant, chinese_case, value as u128)
}
#[inline]
pub fn from_usize_to_chinese_middle(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: usize,
) -> String {
from_u128_to_chinese_middle(chinese_variant, chinese_case, value as u128)
}
#[inline]
pub fn from_usize_to_chinese_high(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: usize,
) -> String {
from_u128_to_chinese_high(chinese_variant, chinese_case, value as u128)
}
#[inline]
pub fn from_i8_to_chinese(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: i8,
) -> String {
from_i128_to_chinese_low(chinese_variant, chinese_case, value as i128).unwrap()
}
#[inline]
pub fn from_i16_to_chinese(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: i16,
) -> String {
from_i128_to_chinese_low(chinese_variant, chinese_case, value as i128).unwrap()
}
#[inline]
pub fn from_i32_to_chinese_low(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: i32,
) -> String {
from_i128_to_chinese_low(chinese_variant, chinese_case, value as i128).unwrap()
}
#[inline]
pub fn from_i32_to_chinese_ten_thousand(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: i32,
) -> String {
from_i128_to_chinese_ten_thousand(chinese_variant, chinese_case, value as i128)
}
#[inline]
pub fn from_i32_to_chinese_middle(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: i32,
) -> String {
from_i128_to_chinese_middle(chinese_variant, chinese_case, value as i128)
}
#[inline]
pub fn from_i32_to_chinese_high(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: i32,
) -> String {
from_i128_to_chinese_high(chinese_variant, chinese_case, value as i128)
}
#[inline]
pub fn from_i64_to_chinese_low(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: i64,
) -> Result<String, NumberToChineseError> {
from_i128_to_chinese_low(chinese_variant, chinese_case, value as i128)
}
#[inline]
pub fn from_i64_to_chinese_ten_thousand(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: i64,
) -> String {
from_i128_to_chinese_ten_thousand(chinese_variant, chinese_case, value as i128)
}
#[inline]
pub fn from_i64_to_chinese_middle(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: i64,
) -> String {
from_i128_to_chinese_middle(chinese_variant, chinese_case, value as i128)
}
#[inline]
pub fn from_i64_to_chinese_high(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: i64,
) -> String {
from_i128_to_chinese_high(chinese_variant, chinese_case, value as i128)
}
#[inline]
pub fn from_i128_to_chinese_low(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: i128,
) -> Result<String, NumberToChineseError> {
if value < 0 {
let mut s =
from_u128_to_chinese_low(chinese_variant, chinese_case, -(value + 1) as u128 + 1)
.map_err(|err| match err {
NumberToChineseError::Overflow => NumberToChineseError::Underflow,
_ => err,
})?;
s.insert_str(0, ChineseSign::負.to_str(chinese_variant));
Ok(s)
} else {
from_u128_to_chinese_low(chinese_variant, chinese_case, value as u128)
}
}
#[inline]
pub fn from_i128_to_chinese_ten_thousand(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: i128,
) -> String {
if value < 0 {
let mut s = from_u128_to_chinese_ten_thousand(
chinese_variant,
chinese_case,
-(value + 1) as u128 + 1,
);
s.insert_str(0, ChineseSign::負.to_str(chinese_variant));
s
} else {
from_u128_to_chinese_ten_thousand(chinese_variant, chinese_case, value as u128)
}
}
#[inline]
pub fn from_i128_to_chinese_middle(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: i128,
) -> String {
if value < 0 {
let mut s =
from_u128_to_chinese_middle(chinese_variant, chinese_case, -(value + 1) as u128 + 1);
s.insert_str(0, ChineseSign::負.to_str(chinese_variant));
s
} else {
from_u128_to_chinese_middle(chinese_variant, chinese_case, value as u128)
}
}
#[inline]
pub fn from_i128_to_chinese_high(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: i128,
) -> String {
if value < 0 {
let mut s =
from_u128_to_chinese_high(chinese_variant, chinese_case, -(value + 1) as u128 + 1);
s.insert_str(0, ChineseSign::負.to_str(chinese_variant));
s
} else {
from_u128_to_chinese_high(chinese_variant, chinese_case, value as u128)
}
}
#[inline]
pub fn from_isize_to_chinese_low(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: isize,
) -> Result<String, NumberToChineseError> {
from_i128_to_chinese_low(chinese_variant, chinese_case, value as i128)
}
#[inline]
pub fn from_isize_to_chinese_ten_thousand(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: isize,
) -> String {
from_i128_to_chinese_ten_thousand(chinese_variant, chinese_case, value as i128)
}
#[inline]
pub fn from_isize_to_chinese_middle(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: isize,
) -> String {
from_i128_to_chinese_middle(chinese_variant, chinese_case, value as i128)
}
#[inline]
pub fn from_isize_to_chinese_high(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: isize,
) -> String {
from_i128_to_chinese_high(chinese_variant, chinese_case, value as i128)
}
#[inline]
pub fn from_f32_to_chinese_low(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: f32,
) -> Result<String, NumberToChineseError> {
from_f64_to_chinese_low(chinese_variant, chinese_case, value as f64)
}
#[inline]
pub fn from_f32_to_chinese_ten_thousand(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: f32,
) -> String {
from_f64_to_chinese_ten_thousand(chinese_variant, chinese_case, value as f64).unwrap()
}
#[inline]
pub fn from_f32_to_chinese_middle(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: f32,
) -> String {
from_f64_to_chinese_middle(chinese_variant, chinese_case, value as f64).unwrap()
}
#[inline]
pub fn from_f32_to_chinese_high(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: f32,
) -> String {
from_f64_to_chinese_high(chinese_variant, chinese_case, value as f64)
}
#[inline]
fn from_f64_to_chinese(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
method: ChineseCountMethod,
value: f64,
) -> String {
if value < 0.0 {
let mut s = positive_float_to_chinese(chinese_variant, chinese_case, method, -value);
s.insert_str(0, ChineseSign::負.to_str(chinese_variant));
s
} else {
positive_float_to_chinese(chinese_variant, chinese_case, method, value)
}
}
#[inline]
pub fn from_f64_to_chinese_low(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: f64,
) -> Result<String, NumberToChineseError> {
if value >= 1_0000_0000_0000_0000f64 {
return Err(NumberToChineseError::Overflow);
} else if value <= -1_0000_0000_0000_0000f64 {
return Err(NumberToChineseError::Underflow);
}
Ok(from_f64_to_chinese(chinese_variant, chinese_case, ChineseCountMethod::Low, value))
}
#[inline]
pub fn from_f64_to_chinese_ten_thousand(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: f64,
) -> Result<String, NumberToChineseError> {
if value >= 1e52 {
return Err(NumberToChineseError::Overflow);
} else if value <= -1e52 {
return Err(NumberToChineseError::Underflow);
}
Ok(from_f64_to_chinese(chinese_variant, chinese_case, ChineseCountMethod::TenThousand, value))
}
#[inline]
pub fn from_f64_to_chinese_middle(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: f64,
) -> Result<String, NumberToChineseError> {
if value >= 1e96 {
return Err(NumberToChineseError::Overflow);
} else if value <= -1e96 {
return Err(NumberToChineseError::Underflow);
}
Ok(from_f64_to_chinese(chinese_variant, chinese_case, ChineseCountMethod::Middle, value))
}
#[inline]
pub fn from_f64_to_chinese_high(
chinese_variant: ChineseVariant,
chinese_case: ChineseCase,
value: f64,
) -> String {
from_f64_to_chinese(chinese_variant, chinese_case, ChineseCountMethod::High, value)
}