#[macro_export]
macro_rules! str_replace {
($input:expr, $pattern:expr, $replace_with:expr $(,)*) => {{
const ARGS_OSRCTFL4A: $crate::__str_methods::ReplaceInput =
$crate::__str_methods::ReplaceInputConv($input, $pattern, $replace_with).conv();
{
const OB: &[$crate::pmr::u8; ARGS_OSRCTFL4A.replace_length()] =
&ARGS_OSRCTFL4A.replace();
const OS: &$crate::pmr::str = unsafe { $crate::__priv_transmute_bytes_to_str!(OB) };
OS
}
}};
}
#[cfg_attr(
feature = "__test",
doc = r##"
```rust
const_format::str_repeat!("hello", usize::MAX.wrapping_add(4));
```
"##
)]
#[macro_export]
macro_rules! str_repeat {
($string:expr, $times:expr $(,)*) => {{
const P_OSRCTFL4A: &$crate::__str_methods::StrRepeatArgs =
&$crate::__str_methods::StrRepeatArgs($string, $times);
{
use $crate::__hidden_utils::PtrToRef;
use $crate::pmr::{str, transmute, u8};
const P: &$crate::__str_methods::StrRepeatArgs = P_OSRCTFL4A;
$crate::pmr::respan_to! {
($string)
const _ASSERT_VALID_LEN: () = P.assert_valid();
}
const OUT_B: &[u8; P.out_len] = &unsafe {
let ptr = P.str.as_ptr() as *const [u8; P.str_len];
transmute::<[[u8; P.str_len]; P.repeat], [u8; P.out_len]>(
[*PtrToRef { ptr }.reff; P.repeat],
)
};
const OUT_S: &str = unsafe { $crate::__priv_transmute_bytes_to_str!(OUT_B) };
OUT_S
}
}};
}
#[cfg_attr(
feature = "__test",
doc = r#"
```rust
const_format::str_splice!("foo", 0..3, "");
```
```compile_fail
const_format::str_splice!("foo", 0..usize::MAX, "");
```
```rust
assert_eq!(
const_format::str_splice!("効率的", 3..6, "A"),
const_format::SplicedStr{output: "効A的", removed: "率"} ,
);
```
```compile_fail
assert_eq!(
const_format::str_splice!("効率的", 1..6, "A"),
const_format::SplicedStr{output: "効A的", removed: "率"} ,
);
```
```compile_fail
assert_eq!(
const_format::str_splice!("効率的", 3..5, "A"),
const_format::SplicedStr{output: "効A的", removed: "率"} ,
);
```
"#
)]
#[macro_export]
macro_rules! str_splice {
($string:expr, $index:expr, $insert:expr $(,)*) => {{
const P_OSRCTFL4A: $crate::__str_methods::StrSpliceArgs =
$crate::__str_methods::StrSplceArgsConv($string, $index, $insert).conv();
{
use $crate::__hidden_utils::PtrToRef;
use $crate::__str_methods::{DecomposedString, SplicedStr, StrSpliceArgs};
use $crate::pmr::{str, u8};
const P: &StrSpliceArgs = &P_OSRCTFL4A;
type DecompIn =
DecomposedString<[u8; P.used_rstart], [u8; P.used_rlen], [u8; P.suffix_len]>;
type DecompOut =
DecomposedString<[u8; P.used_rstart], [u8; P.insert_len], [u8; P.suffix_len]>;
$crate::pmr::respan_to! {
($string)
const _ASSERT_VALID_INDEX: () = P.index_validity.assert_valid();
}
const OUT_A: (&DecompOut, &str) = unsafe {
let input = PtrToRef {
ptr: P.str.as_ptr() as *const DecompIn,
}
.reff;
let insert = PtrToRef {
ptr: P.insert.as_ptr() as *const [u8; P.insert_len],
}
.reff;
(
&DecomposedString {
prefix: input.prefix,
middle: *insert,
suffix: input.suffix,
},
$crate::__priv_transmute_bytes_to_str!(&input.middle),
)
};
const OUT: SplicedStr = unsafe {
let output = OUT_A.0 as *const DecompOut as *const [u8; P.out_len];
SplicedStr {
output: $crate::__priv_transmute_raw_bytes_to_str!(output),
removed: OUT_A.1,
}
};
OUT
}
}};
}
#[cfg_attr(
feature = "__test",
doc = r#"
```rust
assert_eq!(const_format::str_index!("効率的", 3..6), "率");
```
```compile_fail
assert_eq!(const_format::str_index!("効率的", 3..5), "率");
```
```compile_fail
assert_eq!(const_format::str_index!("効率的", 4..6), "率");
```
"#
)]
#[macro_export]
macro_rules! str_index {
($string:expr, $index:expr $(,)*) => {{
const P_OSRCTFL4A: $crate::__str_methods::StrIndexArgs =
$crate::__str_methods::StrIndexArgsConv($string, $index).conv();
{
$crate::pmr::respan_to! {
($string)
const _ASSERT_VALID_INDEX: () =
P_OSRCTFL4A.index_validity.assert_valid();
}
use $crate::__hidden_utils::PtrToRef;
use $crate::__str_methods::DecomposedString;
type DecompIn = DecomposedString<
[u8; P_OSRCTFL4A.used_rstart],
[u8; P_OSRCTFL4A.used_rlen],
[u8; 0],
>;
const OUT: &'static str = unsafe {
let input = PtrToRef {
ptr: P_OSRCTFL4A.str.as_ptr() as *const DecompIn,
}
.reff;
$crate::__priv_transmute_raw_bytes_to_str!(&input.middle)
};
OUT
}
}};
}
#[cfg_attr(
feature = "__test",
doc = r#"
```rust
assert_eq!(const_format::str_get!("効率的", 3..6), Some("率"));
assert_eq!(const_format::str_get!("効率的", 3..5), None);
assert_eq!(const_format::str_get!("効率的", 4..6), None);
```
"#
)]
#[macro_export]
macro_rules! str_get {
($string:expr, $index:expr $(,)*) => {{
const P_OSRCTFL4A: $crate::__str_methods::StrIndexArgs =
$crate::__str_methods::StrIndexArgsConv($string, $index).conv();
{
use $crate::__hidden_utils::PtrToRef;
use $crate::__str_methods::DecomposedString;
type DecompIn = DecomposedString<
[u8; P_OSRCTFL4A.used_rstart],
[u8; P_OSRCTFL4A.used_rlen],
[u8; 0],
>;
const OUT: $crate::pmr::Option<&'static $crate::pmr::str> = unsafe {
if P_OSRCTFL4A.index_validity.is_valid() {
let input = PtrToRef {
ptr: P_OSRCTFL4A.str.as_ptr() as *const DecompIn,
}
.reff;
$crate::pmr::Some($crate::__priv_transmute_raw_bytes_to_str!(&input.middle))
} else {
$crate::pmr::None
}
};
OUT
}
}};
}
#[macro_export]
#[cfg(feature = "rust_1_64")]
#[cfg_attr(feature = "__docsrs", doc(cfg(feature = "rust_1_64")))]
macro_rules! str_split {
($string:expr, $splitter:expr $(,)?) => {{
const ARGS_OSRCTFL4A: $crate::__str_methods::SplitInput =
$crate::__str_methods::SplitInputConv($string, $splitter).conv();
{
const OB: [&$crate::pmr::str; ARGS_OSRCTFL4A.length()] = ARGS_OSRCTFL4A.split_it();
OB
}
}};
}