mirror of
https://github.com/tailix/libkernaux.git
synced 2024-11-13 11:04:27 -05:00
Rust: split "ntoa::[u|i]toa" funcs
This commit is contained in:
parent
ea3cee8612
commit
841d2d20e8
1 changed files with 21 additions and 13 deletions
|
@ -30,9 +30,6 @@ pub enum Error {
|
|||
}
|
||||
|
||||
pub fn utoa(value: u64, config: Config, prefix: Option<&str>) -> Result {
|
||||
let mut buffer: [i8; UTOA_MIN_BUFFER_SIZE + MAX_PREFIX_LEN] =
|
||||
[0; UTOA_MIN_BUFFER_SIZE + MAX_PREFIX_LEN];
|
||||
|
||||
let prefix = if let Some(prefix) = prefix {
|
||||
if prefix.len() > MAX_PREFIX_LEN {
|
||||
return Err(Error::PrefixTooLong(prefix.len()));
|
||||
|
@ -42,6 +39,26 @@ pub fn utoa(value: u64, config: Config, prefix: Option<&str>) -> Result {
|
|||
None
|
||||
};
|
||||
|
||||
utoac(value, config, prefix)
|
||||
}
|
||||
|
||||
pub fn itoa(value: i64, config: Config, prefix: Option<&str>) -> Result {
|
||||
let prefix = if let Some(prefix) = prefix {
|
||||
if prefix.len() > MAX_PREFIX_LEN {
|
||||
return Err(Error::PrefixTooLong(prefix.len()));
|
||||
}
|
||||
Some(CString::new(prefix)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
itoac(value, config, prefix)
|
||||
}
|
||||
|
||||
fn utoac(value: u64, config: Config, prefix: Option<CString>) -> Result {
|
||||
let mut buffer: [i8; UTOA_MIN_BUFFER_SIZE + MAX_PREFIX_LEN] =
|
||||
[0; UTOA_MIN_BUFFER_SIZE + MAX_PREFIX_LEN];
|
||||
|
||||
unsafe {
|
||||
kernaux_utoa(
|
||||
value,
|
||||
|
@ -58,19 +75,10 @@ pub fn utoa(value: u64, config: Config, prefix: Option<&str>) -> Result {
|
|||
Ok(String::from(result))
|
||||
}
|
||||
|
||||
pub fn itoa(value: i64, config: Config, prefix: Option<&str>) -> Result {
|
||||
fn itoac(value: i64, config: Config, prefix: Option<CString>) -> Result {
|
||||
let mut buffer: [i8; ITOA_MIN_BUFFER_SIZE + MAX_PREFIX_LEN] =
|
||||
[0; ITOA_MIN_BUFFER_SIZE + MAX_PREFIX_LEN];
|
||||
|
||||
let prefix = if let Some(prefix) = prefix {
|
||||
if prefix.len() > MAX_PREFIX_LEN {
|
||||
return Err(Error::PrefixTooLong(prefix.len()));
|
||||
}
|
||||
Some(CString::new(prefix)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
unsafe {
|
||||
kernaux_itoa(
|
||||
value,
|
||||
|
|
Loading…
Reference in a new issue