mod arg;
pub use arg::{Arg, ToArg};
mod fmt_fp;
mod printf_impl;
pub use printf_impl::{sprintf_locale, Error, FormatString};
pub mod locale;
pub use locale::{Locale, C_LOCALE, EN_US_LOCALE};
#[cfg(test)]
mod tests;
#[macro_export]
macro_rules! sprintf {
(
$fmt:expr, // Format string, which should implement FormatString.
$($arg:expr),* // arguments
$(,)? // optional trailing comma
) => {
{
let mut target = String::new();
$crate::sprintf!(=> &mut target, $fmt, $($arg),*);
target
}
};
(
=> $target:expr, // target string
$fmt:expr, // format string
$($arg:expr),* // arguments
$(,)? // optional trailing comma
) => {
{
#[allow(unused_imports)]
use $crate::ToArg;
$crate::printf_c_locale(
$target,
$fmt,
&mut [$($arg.to_arg()),*],
).unwrap()
}
};
}
pub fn printf_c_locale(
f: &mut impl std::fmt::Write,
fmt: impl FormatString,
args: &mut [Arg],
) -> Result<usize, Error> {
sprintf_locale(f, fmt, &locale::C_LOCALE, args)
}