slash_formatter/file_separator_build.rs
1use alloc::{borrow::Cow, string::String};
2
3/// Delete an ending ``FILE_SEPARATOR_ON_WORKSTATION`` in a string except for just ``FILE_SEPARATOR_ON_WORKSTATION``.
4///
5/// ```
6/// assert_eq!(
7/// "path",
8/// slash_formatter::delete_end_file_separator_build(concat!(
9/// "path",
10/// slash_formatter::file_separator_build!()
11/// ))
12/// );
13/// ```
14#[inline]
15pub fn delete_end_file_separator_build<S: ?Sized + AsRef<str>>(s: &S) -> &str {
16 #[cfg(from_unix)]
17 {
18 crate::delete_end_slash(s)
19 }
20
21 #[cfg(from_windows)]
22 {
23 crate::delete_end_backslash(s)
24 }
25}
26
27/// Delete an ending ``FILE_SEPARATOR_ON_WORKSTATION`` in a string except for just ``FILE_SEPARATOR_ON_WORKSTATION``.
28///
29/// ```
30/// let mut s =
31/// String::from(concat!("path", slash_formatter::file_separator_build!()));
32///
33/// slash_formatter::delete_end_file_separator_build_in_place(&mut s);
34///
35/// assert_eq!("path", s);
36/// ```
37#[inline]
38pub fn delete_end_file_separator_build_in_place(s: &mut String) {
39 #[cfg(from_unix)]
40 {
41 crate::delete_end_slash_in_place(s)
42 }
43
44 #[cfg(from_windows)]
45 {
46 crate::delete_end_backslash_in_place(s)
47 }
48}
49
50/// Delete a starting ``FILE_SEPARATOR_ON_WORKSTATION`` in a string except for just ``FILE_SEPARATOR_ON_WORKSTATION``.
51///
52/// ```
53/// assert_eq!(
54/// "path",
55/// slash_formatter::delete_start_file_separator_build(concat!(
56/// slash_formatter::file_separator_build!(),
57/// "path"
58/// ))
59/// );
60/// ```
61#[inline]
62pub fn delete_start_file_separator_build<S: ?Sized + AsRef<str>>(s: &S) -> &str {
63 #[cfg(from_unix)]
64 {
65 crate::delete_start_slash(s)
66 }
67
68 #[cfg(from_windows)]
69 {
70 crate::delete_start_backslash(s)
71 }
72}
73
74/// Delete a starting ``FILE_SEPARATOR_ON_WORKSTATION`` in a string except for just ``FILE_SEPARATOR_ON_WORKSTATION``.
75///
76/// ```
77/// let mut s =
78/// String::from(concat!(slash_formatter::file_separator_build!(), "path"));
79///
80/// slash_formatter::delete_start_file_separator_build_in_place(&mut s);
81///
82/// assert_eq!("path", s);
83/// ```
84#[inline]
85pub fn delete_start_file_separator_build_in_place(s: &mut String) {
86 #[cfg(from_unix)]
87 {
88 crate::delete_start_slash_in_place(s)
89 }
90
91 #[cfg(from_windows)]
92 {
93 crate::delete_start_backslash_in_place(s)
94 }
95}
96
97/// Add a starting ``FILE_SEPARATOR_ON_WORKSTATION`` into a string.
98///
99/// ```
100/// assert_eq!(
101/// concat!(slash_formatter::file_separator_build!(), "path"),
102/// slash_formatter::add_start_file_separator_build("path")
103/// );
104/// ```
105#[inline]
106pub fn add_start_file_separator_build<S: ?Sized + AsRef<str>>(s: &S) -> Cow<str> {
107 #[cfg(from_unix)]
108 {
109 crate::add_start_slash(s)
110 }
111
112 #[cfg(from_windows)]
113 {
114 crate::add_start_backslash(s)
115 }
116}
117
118/// Add a starting ``FILE_SEPARATOR_ON_WORKSTATION`` into a string.
119///
120/// ```
121/// let mut s = String::from("path");
122///
123/// slash_formatter::add_start_file_separator_build_in_place(&mut s);
124///
125/// assert_eq!(concat!(slash_formatter::file_separator_build!(), "path"), s);
126/// ```
127#[inline]
128pub fn add_start_file_separator_build_in_place(s: &mut String) {
129 #[cfg(from_unix)]
130 {
131 crate::add_start_slash_in_place(s)
132 }
133
134 #[cfg(from_windows)]
135 {
136 crate::add_start_backslash_in_place(s)
137 }
138}
139
140/// Add an ending ``FILE_SEPARATOR_ON_WORKSTATION`` into a string.
141///
142/// ```
143/// assert_eq!(
144/// concat!("path", slash_formatter::file_separator_build!()),
145/// slash_formatter::add_end_file_separator_build("path")
146/// );
147/// ```
148#[inline]
149pub fn add_end_file_separator_build<S: ?Sized + AsRef<str>>(s: &S) -> Cow<str> {
150 #[cfg(from_unix)]
151 {
152 crate::add_end_slash(s)
153 }
154
155 #[cfg(from_windows)]
156 {
157 crate::add_end_backslash(s)
158 }
159}
160
161/// Add an ending ``FILE_SEPARATOR_ON_WORKSTATION`` into a string.
162///
163/// ```
164/// let mut s = String::from("path");
165///
166/// slash_formatter::add_end_file_separator_build_in_place(&mut s);
167///
168/// assert_eq!(concat!("path", slash_formatter::file_separator_build!()), s);
169/// ```
170#[inline]
171pub fn add_end_file_separator_build_in_place(s: &mut String) {
172 #[cfg(from_unix)]
173 {
174 crate::add_end_slash_in_place(s)
175 }
176
177 #[cfg(from_windows)]
178 {
179 crate::add_end_backslash_in_place(s)
180 }
181}
182
183/// Concatenate two strings with ``FILE_SEPARATOR_ON_WORKSTATION``.
184///
185/// ```
186/// assert_eq!(
187/// concat!("path", slash_formatter::file_separator_build!(), "to"),
188/// slash_formatter::concat_with_file_separator_build(
189/// "path",
190/// concat!("to", slash_formatter::file_separator_build!())
191/// )
192/// );
193/// ```
194#[inline]
195pub fn concat_with_file_separator_build<S1: Into<String>, S2: AsRef<str>>(
196 s1: S1,
197 s2: S2,
198) -> String {
199 #[cfg(from_unix)]
200 {
201 crate::concat_with_slash(s1, s2)
202 }
203
204 #[cfg(from_windows)]
205 {
206 crate::concat_with_backslash(s1, s2)
207 }
208}
209
210/// Concatenate two strings with ``FILE_SEPARATOR_ON_WORKSTATION``.
211///
212/// ```
213/// let mut s = String::from("path");
214///
215/// slash_formatter::concat_with_file_separator_build_in_place(
216/// &mut s,
217/// concat!("to", slash_formatter::file_separator_build!()),
218/// );
219///
220/// assert_eq!(
221/// concat!("path", slash_formatter::file_separator_build!(), "to"),
222/// s
223/// );
224/// ```
225#[inline]
226pub fn concat_with_file_separator_build_in_place<S2: AsRef<str>>(s1: &mut String, s2: S2) {
227 #[cfg(from_unix)]
228 {
229 crate::concat_with_slash_in_place(s1, s2)
230 }
231
232 #[cfg(from_windows)]
233 {
234 crate::concat_with_backslash_in_place(s1, s2)
235 }
236}
237
238#[cfg(from_unix)]
239/**
240Concatenate multiple strings with ``FILE_SEPARATOR_ON_WORKSTATION``. It can also be used to get the literal ``FILE_SEPARATOR_ON_WORKSTATION``.
241
242```
243assert_eq!(slash_formatter::concat_with_file_separator_build!("path", "to", "file"), slash_formatter::file_separator_build!("path", concat!("to", slash_formatter::file_separator_build!()), concat!(slash_formatter::file_separator_build!(), "file", slash_formatter::file_separator_build!())));
244
245let s = String::from("path");
246
247let s = slash_formatter::file_separator_build!(s, concat!("to", slash_formatter::file_separator_build!()), concat!(slash_formatter::file_separator_build!(), "file", slash_formatter::file_separator_build!()));
248
249assert_eq!(slash_formatter::concat_with_file_separator_build!("path", "to", "file"), s);
250```
251*/
252#[macro_export]
253macro_rules! file_separator_build {
254 ($($t:tt)*) => {
255 $crate::slash!($($t)*)
256 };
257}
258
259#[cfg(from_windows)]
260/**
261Concatenate multiple strings with ``FILE_SEPARATOR_ON_WORKSTATION``. It can also be used to get the literal ``FILE_SEPARATOR_ON_WORKSTATION``.
262
263```
264assert_eq!(slash_formatter::concat_with_file_separator_build!("path", "to", "file"), slash_formatter::file_separator_build!("path", concat!("to", slash_formatter::file_separator_build!()), concat!(slash_formatter::file_separator_build!(), "file", slash_formatter::file_separator_build!())));
265
266let s = String::from("path");
267
268let s = slash_formatter::file_separator_build!(s, concat!("to", slash_formatter::file_separator_build!()), concat!(slash_formatter::file_separator_build!(), "file", slash_formatter::file_separator_build!()));
269
270assert_eq!(slash_formatter::concat_with_file_separator_build!("path", "to", "file"), s);
271```
272*/
273#[macro_export]
274macro_rules! file_separator_build {
275 ($($t:tt)*) => {
276 $crate::backslash!($($t)*)
277 };
278}
279
280#[cfg(from_unix)]
281/**
282Concatenate multiple strings with ``FILE_SEPARATOR_ON_WORKSTATION``. It can also be used to get the literal ``FILE_SEPARATOR_ON_WORKSTATION``.
283
284```
285let mut s = String::from("path");
286
287slash_formatter::file_separator_build_in_place!(&mut s, concat!("to", slash_formatter::file_separator_build!()), concat!(slash_formatter::file_separator_build!(), "file", slash_formatter::file_separator_build!()));
288
289assert_eq!(slash_formatter::concat_with_file_separator_build!("path", "to", "file"), s);
290```
291*/
292#[macro_export]
293macro_rules! file_separator_build_in_place {
294 ($($t:tt)*) => {
295 $crate::slash_in_place!($($t)*)
296 };
297}
298
299#[cfg(from_windows)]
300/**
301Concatenate multiple strings with ``FILE_SEPARATOR_ON_WORKSTATION``. It can also be used to get the literal ``FILE_SEPARATOR_ON_WORKSTATION``.
302
303```
304let mut s = String::from("path");
305
306slash_formatter::file_separator_build_in_place!(&mut s, concat!("to", slash_formatter::file_separator_build!()), concat!(slash_formatter::file_separator_build!(), "file", slash_formatter::file_separator_build!()));
307
308assert_eq!(slash_formatter::concat_with_file_separator_build!("path", "to", "file"), s);
309```
310*/
311#[macro_export]
312macro_rules! file_separator_build_in_place {
313 ($($t:tt)*) => {
314 $crate::backslash_in_place!($($t)*)
315 };
316}
317
318#[cfg(from_unix)]
319/**
320Concatenates literals into a static string slice separated by ``FILE_SEPARATOR_ON_WORKSTATION``. Prefixes and suffixes can also be added.
321
322```
323assert_eq!(concat!("test", slash_formatter::file_separator_build!(), 10, slash_formatter::file_separator_build!(), 'b', slash_formatter::file_separator_build!(), true), slash_formatter::concat_with_file_separator_build!("test", 10, 'b', true));
324```
325*/
326#[macro_export]
327macro_rules! concat_with_file_separator_build {
328 ($($t:tt)*) => {
329 $crate::concat_with_slash!($($t)*)
330 };
331}
332
333#[cfg(from_windows)]
334/**
335Concatenates literals into a static string slice separated by ``FILE_SEPARATOR_ON_WORKSTATION``. Prefixes and suffixes can also be added.
336
337```
338assert_eq!(concat!("test", slash_formatter::file_separator_build!(), 10, slash_formatter::file_separator_build!(), 'b', slash_formatter::file_separator_build!(), true), slash_formatter::concat_with_file_separator_build!("test", 10, 'b', true));
339```
340*/
341#[macro_export]
342macro_rules! concat_with_file_separator_build {
343 ($($t:tt)*) => {
344 $crate::concat_with_backslash!($($t)*)
345 };
346}
347
348#[cfg(debug_assertions)]
349/**
350Concatenates literals into a static string slice separated by file separators which depends on the target OS if in debug mode, or depends on the workstation if in release mode. Prefixes and suffixes can also be added.
351
352```
353if cfg!(debug_assertions) {
354 assert_eq!(concat!("test", slash_formatter::file_separator!(), 10, slash_formatter::file_separator!(), 'b', slash_formatter::file_separator!(), true), slash_formatter::concat_with_file_separator_debug_release!("test", 10, 'b', true));
355}
356
357if !cfg!(debug_assertions) {
358 assert_eq!(concat!("test", slash_formatter::file_separator_build!(), 10, slash_formatter::file_separator_build!(), 'b', slash_formatter::file_separator_build!(), true), slash_formatter::concat_with_file_separator_debug_release!("test", 10, 'b', true));
359}
360```
361*/
362#[macro_export]
363macro_rules! concat_with_file_separator_debug_release {
364 ($($t:tt)*) => {
365 $crate::concat_with_file_separator!($($t)*)
366 };
367}
368
369#[cfg(not(debug_assertions))]
370/**
371Concatenates literals into a static string slice separated by file separators which dependents on the target OS if in debug mode, or dependents on the workstation if in release mode. Prefixes and suffixes can also be added.
372
373```
374if cfg!(debug_assertions) {
375 assert_eq!(concat!("test", slash_formatter::file_separator!(), 10, slash_formatter::file_separator!(), 'b', slash_formatter::file_separator!(), true), slash_formatter::concat_with_file_separator_debug_release!("test", 10, 'b', true));
376}
377
378if !cfg!(debug_assertions) {
379 assert_eq!(concat!("test", slash_formatter::file_separator_build!(), 10, slash_formatter::file_separator_build!(), 'b', slash_formatter::file_separator_build!(), true), slash_formatter::concat_with_file_separator_debug_release!("test", 10, 'b', true));
380}
381```
382*/
383#[macro_export]
384macro_rules! concat_with_file_separator_debug_release {
385 ($($t:tt)*) => {
386 $crate::concat_with_file_separator_build!($($t)*)
387 };
388}