url_cleaner_engine/tutorial/cleaner/
string_modification.rs

1//! # [`StringModification`]
2//!
3//! Often, you want to modify a string before using it.
4//!
5//! For example you may want to get a URL's query then
6//!
7//! 1. Split it on `/` and keep only the third segment.
8//!
9//! 2. Remove the first character.
10//!
11//! 3. Base64 decode it using the default URL safe alphabet.
12//!
13//! 4. Split it on `,` and keep only the last segment.
14//!
15//! 5. Replace the URL being cleaned with that segment.
16//!
17//! While this seems like and is a bizarre example, this exact process is used to clean the links cnn sends you in emails.
18//!
19//! To express the above operations, we would write a [`StringSource::Modified`] as follows:
20//!
21//! ```Json
22//! {"SetWhole": {"Modified": {
23//!   "value": {"Part": "Query"},
24//!   "modification": {"All": [
25//!     {"KeepNthSegment": {"split": "/", "index": 2}},
26//!     {"RemoveChar": 0},
27//!     "Base64Decode",
28//!     {"KeepNthSegment": {"split": ",", "index": -1}}
29//!   ]}
30//! }}}
31//! ```
32
33pub(crate) use super::*;