1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//! lit-mod is a collection of procedural macros for working with string literals.
//!
//! ## Usage
//!
//! Add this to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! lit-mod = "0.1"
//! ```
use TokenStream;
/// Replaces all matches of a pattern with another string in a string literal.
///
/// Alternatively the third argument can be ignored and the macro will remove all matches of the
/// pattern instead.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use lit_mod::replace;
///
/// assert_eq!("this is new", replace!("this is old", "old", "new"));
/// assert_eq!("than an old", replace!("this is old", "is", "an"));
/// assert_eq!("this is", replace!("this is old", " old"));
/// ```
///
/// When the pattern doesn't match:
///
/// ```
/// use lit_mod::replace;
///
/// assert_eq!(
/// "this is old",
/// replace!("this is old", "cookie monster", "little lamb")
/// );
/// ```
/// Replaces the literal with a slice of the literal.
///
/// *Note:* This macro doesn't slice by bytes, but by characters.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use lit_mod::slice;
///
/// assert_eq!("world!", slice!("Hello, world!", 7..));
/// assert_eq!("Hello", slice!("Hello, world!", ..-8));
/// ```
/// Replaces the literal with a literal of the lines.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use lit_mod::lines;
///
/// assert_eq!(
/// "Hello, world!",
/// lines!("Hello, world!\nThis is lines", 0..1)
/// );
/// assert_eq!(
/// "This is lines",
/// lines!("Hello, world!\nThis is lines", -1..)
/// );
/// ```
/// Replaces the literal with a literal without the lines.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use lit_mod::remove_lines;
///
/// assert_eq!(
/// "Hello, world!",
/// remove_lines!("Hello, world!\nThis is lines", -1..)
/// );
/// assert_eq!(
/// "This is lines",
/// remove_lines!("Hello, world!\nThis is lines", ..1)
/// );
/// ```