rstring 0.1.0

A comprehensive set of string manipulation utilities inspired by Apache Commons Lang3 StringUtils
Documentation
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
//! Character and substring removal utilities.
//!
//! This module provides functions for removing prefixes, suffixes, characters,
//! substrings, and whitespace from strings.
//!
//! # Usage
//!
//! Import the [`StringRemove`] trait to use methods directly on strings:
//!
//! ```
//! use rstring::StringRemove;
//!
//! assert_eq!("www.domain.com".remove_start("www."), "domain.com");
//! assert_eq!("www.domain.com".remove_end(".com"), "www.domain");
//! assert_eq!("queued".remove_occurrence("ue"), "qd");
//! assert_eq!("  ab  c  ".delete_whitespace(), "abc");
//! ```

use std::borrow::Cow;

use crate::shared::{
    ends_with_ignore_ascii_case, ends_with_ignore_case, starts_with_ignore_ascii_case,
    starts_with_ignore_case,
};

/// Extension trait for string removal methods.
///
/// This trait is implemented for `str`, allowing you to call removal
/// methods directly on `&str`, `String`, and other string types.
///
/// # Examples
///
/// ```
/// use rstring::StringRemove;
///
/// // Prefix/suffix removal
/// assert_eq!("/path/to/file".remove_start("/"), "path/to/file");
/// assert_eq!("file.txt".remove_end(".txt"), "file");
///
/// // Substring removal
/// assert_eq!("queued".remove_occurrence("ue"), "qd");
/// assert_eq!("quEUed".remove_ignore_case("UE"), "qd");
///
/// // Whitespace removal
/// assert_eq!("  ab  c  ".delete_whitespace(), "abc");
/// ```
pub trait StringRemove {
    /// Removes the prefix from the start of the string if present.
    ///
    /// Returns the string unchanged if the prefix is empty or not found.
    ///
    /// # Examples
    ///
    /// ```
    /// use rstring::StringRemove;
    ///
    /// assert_eq!("".remove_start(""), "");
    /// assert_eq!("www.domain.com".remove_start("www."), "domain.com");
    /// assert_eq!("domain.com".remove_start("www."), "domain.com");
    /// assert_eq!("www.domain.com".remove_start("WWW."), "www.domain.com");
    /// ```
    #[must_use]
    fn remove_start(&self, prefix: &str) -> &str;

    /// Removes the prefix from the start of the string if present
    /// (ASCII case-insensitive comparison).
    ///
    /// Only handles A-Z/a-z case folding. For full Unicode support, use
    /// [`remove_start_ignore_case`](StringRemove::remove_start_ignore_case).
    ///
    /// Returns the string unchanged if the prefix is empty or not found.
    ///
    /// # Examples
    ///
    /// ```
    /// use rstring::StringRemove;
    ///
    /// assert_eq!("".remove_start_ignore_ascii_case(""), "");
    /// assert_eq!("www.domain.com".remove_start_ignore_ascii_case("www."), "domain.com");
    /// assert_eq!("www.domain.com".remove_start_ignore_ascii_case("WWW."), "domain.com");
    /// assert_eq!("domain.com".remove_start_ignore_ascii_case("www."), "domain.com");
    /// ```
    #[must_use]
    fn remove_start_ignore_ascii_case(&self, prefix: &str) -> &str;

    /// Removes the prefix from the start of the string if present
    /// (Unicode case-insensitive comparison).
    ///
    /// Handles full Unicode case folding (e.g., é/É, ñ/Ñ) but requires allocation
    /// for the comparison. For ASCII-only strings, prefer
    /// [`remove_start_ignore_ascii_case`](StringRemove::remove_start_ignore_ascii_case).
    ///
    /// Returns the string unchanged if the prefix is empty or not found.
    ///
    /// # Examples
    ///
    /// ```
    /// use rstring::StringRemove;
    ///
    /// assert_eq!("".remove_start_ignore_case(""), "");
    /// assert_eq!("www.domain.com".remove_start_ignore_case("www."), "domain.com");
    /// assert_eq!("www.domain.com".remove_start_ignore_case("WWW."), "domain.com");
    /// assert_eq!("domain.com".remove_start_ignore_case("www."), "domain.com");
    /// assert_eq!("Éclair".remove_start_ignore_case("é"), "clair");
    /// ```
    #[must_use]
    fn remove_start_ignore_case(&self, prefix: &str) -> &str;

    /// Removes the first character from the string if it matches the given character.
    ///
    /// Returns the string unchanged if the character is not found.
    ///
    /// # Examples
    ///
    /// ```
    /// use rstring::StringRemove;
    ///
    /// assert_eq!("".remove_start_char('/'), "");
    /// assert_eq!("/path".remove_start_char('/'), "path");
    /// assert_eq!("path".remove_start_char('/'), "path");
    /// ```
    #[must_use]
    fn remove_start_char(&self, c: char) -> &str;

    /// Removes the suffix from the end of the string if present.
    ///
    /// Returns the string unchanged if the suffix is empty or not found.
    ///
    /// # Examples
    ///
    /// ```
    /// use rstring::StringRemove;
    ///
    /// assert_eq!("".remove_end(""), "");
    /// assert_eq!("www.domain.com".remove_end(".com"), "www.domain");
    /// assert_eq!("www.domain.com.".remove_end(".com"), "www.domain.com.");
    /// assert_eq!("www.domain.com".remove_end(".COM"), "www.domain.com");
    /// ```
    #[must_use]
    fn remove_end(&self, suffix: &str) -> &str;

    /// Removes the suffix from the end of the string if present
    /// (ASCII case-insensitive comparison).
    ///
    /// Only handles A-Z/a-z case folding. For full Unicode support, use
    /// [`remove_end_ignore_case`](StringRemove::remove_end_ignore_case).
    ///
    /// Returns the string unchanged if the suffix is empty or not found.
    ///
    /// # Examples
    ///
    /// ```
    /// use rstring::StringRemove;
    ///
    /// assert_eq!("".remove_end_ignore_ascii_case(""), "");
    /// assert_eq!("www.domain.com".remove_end_ignore_ascii_case(".com"), "www.domain");
    /// assert_eq!("www.domain.COM".remove_end_ignore_ascii_case(".com"), "www.domain");
    /// assert_eq!("www.domain.com.".remove_end_ignore_ascii_case(".com"), "www.domain.com.");
    /// ```
    #[must_use]
    fn remove_end_ignore_ascii_case(&self, suffix: &str) -> &str;

    /// Removes the suffix from the end of the string if present
    /// (Unicode case-insensitive comparison).
    ///
    /// Handles full Unicode case folding (e.g., é/É, ñ/Ñ) but requires allocation
    /// for the comparison. For ASCII-only strings, prefer
    /// [`remove_end_ignore_ascii_case`](StringRemove::remove_end_ignore_ascii_case).
    ///
    /// Returns the string unchanged if the suffix is empty or not found.
    ///
    /// # Examples
    ///
    /// ```
    /// use rstring::StringRemove;
    ///
    /// assert_eq!("".remove_end_ignore_case(""), "");
    /// assert_eq!("www.domain.com".remove_end_ignore_case(".com"), "www.domain");
    /// assert_eq!("www.domain.COM".remove_end_ignore_case(".com"), "www.domain");
    /// assert_eq!("www.domain.com.".remove_end_ignore_case(".com"), "www.domain.com.");
    /// assert_eq!("caféÉ".remove_end_ignore_case("É"), "café");
    /// ```
    #[must_use]
    fn remove_end_ignore_case(&self, suffix: &str) -> &str;

    /// Removes the last character from the string if it matches the given character.
    ///
    /// Returns the string unchanged if the character is not found.
    ///
    /// # Examples
    ///
    /// ```
    /// use rstring::StringRemove;
    ///
    /// assert_eq!("".remove_end_char('/'), "");
    /// assert_eq!("path/".remove_end_char('/'), "path");
    /// assert_eq!("path".remove_end_char('/'), "path");
    /// ```
    #[must_use]
    fn remove_end_char(&self, c: char) -> &str;

    /// Removes all occurrences of a character from the string.
    ///
    /// Returns `Cow::Borrowed` if the character is not found,
    /// `Cow::Owned` otherwise.
    ///
    /// # Examples
    ///
    /// ```
    /// use rstring::StringRemove;
    ///
    /// assert_eq!("".remove_char('u'), "");
    /// assert_eq!("queued".remove_char('u'), "qeed");
    /// assert_eq!("queued".remove_char('z'), "queued");
    /// ```
    #[must_use]
    fn remove_char(&self, c: char) -> Cow<'_, str>;

    /// Removes all occurrences of a substring from the string.
    ///
    /// Returns `Cow::Borrowed` if the substring is empty or not found,
    /// `Cow::Owned` otherwise.
    ///
    /// # Examples
    ///
    /// ```
    /// use rstring::StringRemove;
    ///
    /// assert_eq!("".remove_occurrence("a"), "");
    /// assert_eq!("queued".remove_occurrence("ue"), "qd");
    /// assert_eq!("queued".remove_occurrence("zz"), "queued");
    /// assert_eq!("a".remove_occurrence(""), "a");
    /// ```
    #[must_use]
    fn remove_occurrence(&self, remove: &str) -> Cow<'_, str>;

    /// Removes all occurrences of a substring from the string (case-insensitive).
    ///
    /// Uses Unicode case folding for comparison.
    ///
    /// Returns `Cow::Borrowed` if the substring is empty or not found,
    /// `Cow::Owned` otherwise.
    ///
    /// # Examples
    ///
    /// ```
    /// use rstring::StringRemove;
    ///
    /// assert_eq!("".remove_ignore_case("a"), "");
    /// assert_eq!("queued".remove_ignore_case("ue"), "qd");
    /// assert_eq!("quEUed".remove_ignore_case("UE"), "qd");
    /// assert_eq!("queued".remove_ignore_case("zz"), "queued");
    /// assert_eq!("\u{0130}x".remove_ignore_case("x"), "\u{0130}");
    /// ```
    #[must_use]
    fn remove_ignore_case(&self, remove: &str) -> Cow<'_, str>;

    /// Deletes all whitespace characters from the string as defined by
    /// [`char::is_whitespace`].
    ///
    /// Returns `Cow::Borrowed` if no whitespace was found,
    /// `Cow::Owned` otherwise.
    ///
    /// # Examples
    ///
    /// ```
    /// use rstring::StringRemove;
    ///
    /// assert_eq!("".delete_whitespace(), "");
    /// assert_eq!("abc".delete_whitespace(), "abc");
    /// assert_eq!("   ab  c  ".delete_whitespace(), "abc");
    /// assert_eq!("\u{000B}t  \t\n\u{0009}e\rs\n\n   \tt".delete_whitespace(), "test");
    /// ```
    #[must_use]
    fn delete_whitespace(&self) -> Cow<'_, str>;
}

macro_rules! impl_remove_start_ignore_case {
    ($fn_name:ident, $starts_with_check:expr) => {
        fn $fn_name(&self, prefix: &str) -> &str {
            if !prefix.is_empty() && $starts_with_check(self, prefix) {
                &self[prefix.len()..]
            } else {
                self
            }
        }
    };
}

macro_rules! impl_remove_end_ignore_case {
    ($fn_name:ident, $ends_with_check:expr) => {
        fn $fn_name(&self, suffix: &str) -> &str {
            if !suffix.is_empty() && $ends_with_check(self, suffix) {
                &self[..self.len() - suffix.len()]
            } else {
                self
            }
        }
    };
}

/// Finds the next case-insensitive match of `search` in `s` starting from byte position `start`.
/// Returns `(byte_offset, byte_length_of_match)` or `None` if not found.
///
/// Uses char-by-char comparison with `to_lowercase()` to handle cases where
/// lowercasing changes the number of characters (e.g., Turkish İ → i̇).
fn find_ignore_case(s: &str, search: &str, start: usize) -> Option<(usize, usize)> {
    let search_lower = search.to_lowercase();
    let search_char_count = search.chars().count();
    for (byte_idx, _) in s[start..].char_indices() {
        let abs_byte_idx = start + byte_idx;
        let remaining = &s[abs_byte_idx..];
        let match_byte_len: usize = remaining
            .char_indices()
            .nth(search_char_count)
            .map(|(i, _)| i)
            .unwrap_or(remaining.len());
        let window = &remaining[..match_byte_len];
        if window.to_lowercase() == search_lower {
            return Some((abs_byte_idx, match_byte_len));
        }
    }
    None
}

impl StringRemove for str {
    fn remove_start(&self, prefix: &str) -> &str {
        self.strip_prefix(prefix).unwrap_or(self)
    }

    impl_remove_start_ignore_case!(
        remove_start_ignore_ascii_case,
        starts_with_ignore_ascii_case
    );
    impl_remove_start_ignore_case!(remove_start_ignore_case, starts_with_ignore_case);

    fn remove_start_char(&self, c: char) -> &str {
        self.strip_prefix(c).unwrap_or(self)
    }

    fn remove_end(&self, suffix: &str) -> &str {
        self.strip_suffix(suffix).unwrap_or(self)
    }

    impl_remove_end_ignore_case!(remove_end_ignore_ascii_case, ends_with_ignore_ascii_case);
    impl_remove_end_ignore_case!(remove_end_ignore_case, ends_with_ignore_case);

    fn remove_end_char(&self, c: char) -> &str {
        self.strip_suffix(c).unwrap_or(self)
    }

    fn remove_char(&self, c: char) -> Cow<'_, str> {
        if self.is_empty() || !self.contains(c) {
            return Cow::Borrowed(self);
        }
        Cow::Owned(self.chars().filter(|&ch| ch != c).collect())
    }

    fn remove_occurrence(&self, remove: &str) -> Cow<'_, str> {
        if self.is_empty() || remove.is_empty() || !self.contains(remove) {
            return Cow::Borrowed(self);
        }
        Cow::Owned(self.replace(remove, ""))
    }

    fn remove_ignore_case(&self, remove: &str) -> Cow<'_, str> {
        if self.is_empty() || remove.is_empty() {
            return Cow::Borrowed(self);
        }
        let mut result = String::with_capacity(self.len());
        let mut pos = 0;
        let mut found = false;
        while pos < self.len() {
            if let Some((match_pos, match_len)) = find_ignore_case(self, remove, pos) {
                found = true;
                result.push_str(&self[pos..match_pos]);
                pos = match_pos + match_len;
            } else {
                result.push_str(&self[pos..]);
                break;
            }
        }
        if !found {
            return Cow::Borrowed(self);
        }
        Cow::Owned(result)
    }

    fn delete_whitespace(&self) -> Cow<'_, str> {
        if self.is_empty() || !self.contains(char::is_whitespace) {
            return Cow::Borrowed(self);
        }
        let result: String = self.chars().filter(|c| !c.is_whitespace()).collect();
        if result.is_empty() {
            Cow::Owned(String::new())
        } else {
            Cow::Owned(result)
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    mod remove_start {
        use super::*;

        #[test]
        fn empty_string() {
            assert_eq!("".remove_start(""), "");
        }

        #[test]
        fn empty_prefix() {
            assert_eq!("abc".remove_start(""), "abc");
        }

        #[test]
        fn prefix_present() {
            assert_eq!("www.domain.com".remove_start("www."), "domain.com");
        }

        #[test]
        fn prefix_not_present() {
            assert_eq!("domain.com".remove_start("www."), "domain.com");
        }

        #[test]
        fn prefix_different_case() {
            assert_eq!("www.domain.com".remove_start("WWW."), "www.domain.com");
        }

        #[test]
        fn prefix_partial_match() {
            assert_eq!("wwwdomain.com".remove_start("www."), "wwwdomain.com");
        }
    }

    mod remove_start_ignore_case {
        use super::*;

        #[test]
        fn empty_string() {
            assert_eq!("".remove_start_ignore_case(""), "");
        }

        #[test]
        fn empty_prefix() {
            assert_eq!("abc".remove_start_ignore_case(""), "abc");
        }

        #[test]
        fn prefix_present() {
            assert_eq!(
                "www.domain.com".remove_start_ignore_case("www."),
                "domain.com"
            );
        }

        #[test]
        fn prefix_different_case() {
            assert_eq!(
                "www.domain.com".remove_start_ignore_case("WWW."),
                "domain.com"
            );
        }

        #[test]
        fn prefix_not_present() {
            assert_eq!("domain.com".remove_start_ignore_case("www."), "domain.com");
        }

        #[test]
        fn prefix_mixed_case() {
            assert_eq!(
                "WwW.domain.com".remove_start_ignore_case("www."),
                "domain.com"
            );
        }
    }

    mod remove_start_char {
        use super::*;

        #[test]
        fn empty_string() {
            assert_eq!("".remove_start_char('/'), "");
        }

        #[test]
        fn char_present() {
            assert_eq!("/path".remove_start_char('/'), "path");
        }

        #[test]
        fn char_not_present() {
            assert_eq!("path".remove_start_char('/'), "path");
        }

        #[test]
        fn unicode_char() {
            assert_eq!("\u{00e9}abc".remove_start_char('\u{00e9}'), "abc");
        }

        #[test]
        fn only_char() {
            assert_eq!("/".remove_start_char('/'), "");
        }
    }

    mod remove_end {
        use super::*;

        #[test]
        fn empty_string() {
            assert_eq!("".remove_end(""), "");
        }

        #[test]
        fn empty_suffix() {
            assert_eq!("abc".remove_end(""), "abc");
        }

        #[test]
        fn suffix_present() {
            assert_eq!("www.domain.com".remove_end(".com"), "www.domain");
        }

        #[test]
        fn suffix_not_present() {
            assert_eq!("www.domain.com.".remove_end(".com"), "www.domain.com.");
        }

        #[test]
        fn suffix_different_case() {
            assert_eq!("www.domain.com".remove_end(".COM"), "www.domain.com");
        }

        #[test]
        fn suffix_partial_match() {
            assert_eq!("www.domaincom".remove_end(".com"), "www.domaincom");
        }
    }

    mod remove_end_ignore_case {
        use super::*;

        #[test]
        fn empty_string() {
            assert_eq!("".remove_end_ignore_case(""), "");
        }

        #[test]
        fn empty_suffix() {
            assert_eq!("abc".remove_end_ignore_case(""), "abc");
        }

        #[test]
        fn suffix_present() {
            assert_eq!(
                "www.domain.com".remove_end_ignore_case(".com"),
                "www.domain"
            );
        }

        #[test]
        fn suffix_different_case() {
            assert_eq!(
                "www.domain.COM".remove_end_ignore_case(".com"),
                "www.domain"
            );
        }

        #[test]
        fn suffix_not_present() {
            assert_eq!(
                "www.domain.com.".remove_end_ignore_case(".com"),
                "www.domain.com."
            );
        }

        #[test]
        fn suffix_mixed_case() {
            assert_eq!(
                "www.domain.CoM".remove_end_ignore_case(".com"),
                "www.domain"
            );
        }
    }

    mod remove_end_char {
        use super::*;

        #[test]
        fn empty_string() {
            assert_eq!("".remove_end_char('/'), "");
        }

        #[test]
        fn char_present() {
            assert_eq!("path/".remove_end_char('/'), "path");
        }

        #[test]
        fn char_not_present() {
            assert_eq!("path".remove_end_char('/'), "path");
        }

        #[test]
        fn unicode_char() {
            assert_eq!("abc\u{00e9}".remove_end_char('\u{00e9}'), "abc");
        }

        #[test]
        fn only_char() {
            assert_eq!("/".remove_end_char('/'), "");
        }
    }

    mod remove_char {
        use super::*;

        #[test]
        fn empty_string() {
            assert_eq!("".remove_char('a'), "");
        }

        #[test]
        fn char_present() {
            assert_eq!("queued".remove_char('u'), "qeed");
        }

        #[test]
        fn char_not_present() {
            assert_eq!("queued".remove_char('z'), "queued");
        }

        #[test]
        fn all_chars_match() {
            assert_eq!("aaa".remove_char('a'), "");
        }

        #[test]
        fn unicode_char() {
            assert_eq!("caféé".remove_char('é'), "caf");
        }
    }

    mod remove_occurrence {
        use super::*;

        #[test]
        fn empty_string() {
            assert_eq!("".remove_occurrence("a"), "");
        }

        #[test]
        fn empty_remove() {
            assert_eq!("a".remove_occurrence(""), "a");
        }

        #[test]
        fn substring_present() {
            assert_eq!("queued".remove_occurrence("ue"), "qd");
        }

        #[test]
        fn substring_not_present() {
            assert_eq!("queued".remove_occurrence("zz"), "queued");
        }

        #[test]
        fn multiple_occurrences() {
            assert_eq!("ababa".remove_occurrence("ab"), "a");
        }
    }

    mod remove_ignore_case {
        use super::*;

        #[test]
        fn empty_string() {
            assert_eq!("".remove_ignore_case("a"), "");
        }

        #[test]
        fn empty_remove() {
            assert_eq!("a".remove_ignore_case(""), "a");
        }

        #[test]
        fn exact_case_match() {
            assert_eq!("queued".remove_ignore_case("ue"), "qd");
        }

        #[test]
        fn different_case() {
            assert_eq!("quEUed".remove_ignore_case("UE"), "qd");
        }

        #[test]
        fn no_match() {
            assert_eq!("queued".remove_ignore_case("zz"), "queued");
        }

        #[test]
        fn no_match_different_case() {
            assert_eq!("queued".remove_ignore_case("zZ"), "queued");
        }

        #[test]
        fn unicode_turkish_i() {
            assert_eq!("\u{0130}x".remove_ignore_case("x"), "\u{0130}");
        }

        #[test]
        fn unicode_turkish_i_no_crash() {
            // LANG-1453: should not panic
            let _ = "İa".remove_ignore_case("a");
        }
    }

    mod delete_whitespace {
        use super::*;

        #[test]
        fn empty_string() {
            assert_eq!("".delete_whitespace(), "");
        }

        #[test]
        fn no_whitespace() {
            assert_eq!("abc".delete_whitespace(), "abc");
        }

        #[test]
        fn all_whitespace() {
            assert_eq!(
                "  \u{000C}  \t\t\u{001F}\n\n \u{000B}  ".delete_whitespace(),
                "\u{001F}"
            );
        }

        #[test]
        fn mixed_whitespace_and_text() {
            assert_eq!("   ab  c  ".delete_whitespace(), "abc");
        }

        #[test]
        fn extract_test_from_whitespace() {
            assert_eq!(
                "\u{000B}t  \t\n\u{0009}e\rs\n\n   \tt".delete_whitespace(),
                "test"
            );
        }

        #[test]
        fn only_spaces() {
            assert_eq!("   ".delete_whitespace(), "");
        }

        #[test]
        fn tabs_and_newlines() {
            assert_eq!("\t\n\r".delete_whitespace(), "");
        }
    }

    mod string_types {
        use super::*;

        #[test]
        fn string_ref_remove_start() {
            let s = String::from("www.domain.com");
            assert_eq!(s.remove_start("www."), "domain.com");
        }

        #[test]
        fn boxed_str_remove_end() {
            let s: Box<str> = "file.txt".into();
            assert_eq!(s.remove_end(".txt"), "file");
        }

        #[test]
        fn string_type_remove_char() {
            assert_eq!(String::from("queued").remove_char('u'), "qeed");
        }

        #[test]
        fn string_type_delete_whitespace() {
            assert_eq!(String::from("  ab c  ").delete_whitespace(), "abc");
        }
    }
}