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
//! Byte-slice helpers that complement [`bytes::Bytes`] and [`String`].
//!
//! The C `struct string` is a length-tagged byte view (`uint8_t*` plus
//! `uint32_t`). The Rust port replaces it with [`bytes::Bytes`] for
//! shared ownership of message payloads and [`String`] for textual
//! data. This module collects the small handful of helpers downstream
//! stages reach for: a stripped-down `string_compare` (length-prefixed
//! byte ordering) and char-finding wrappers that operate on slices.
/// Compare two byte slices using the same rule as the C
/// `string_compare`: shorter slices sort first, otherwise sort
/// lexicographically.
///
/// # Examples
///
/// ```
/// use std::cmp::Ordering;
/// use dynomite::util::dyn_string::string_compare;
///
/// assert_eq!(string_compare(b"abc", b"abc"), Ordering::Equal);
/// assert_eq!(string_compare(b"ab", b"abc"), Ordering::Less);
/// assert_eq!(string_compare(b"abd", b"abc"), Ordering::Greater);
/// ```
/// Return the byte index of the first occurrence of `needle` in
/// `haystack`, or [`None`] if absent.
///
/// # Examples
///
/// ```
/// use dynomite::util::dyn_string::strchr;
/// assert_eq!(strchr(b"abcde", b'c'), Some(2));
/// assert_eq!(strchr(b"abcde", b'z'), None);
/// ```
/// Return the byte index of the last occurrence of `needle` in
/// `haystack`, or [`None`] if absent.
///
/// # Examples
///
/// ```
/// use dynomite::util::dyn_string::strrchr;
/// assert_eq!(strrchr(b"abcabc", b'b'), Some(4));
/// assert_eq!(strrchr(b"abcabc", b'z'), None);
/// ```
/// Case-insensitive ASCII slice equality. Slices of different lengths
/// are unequal.
///
/// # Examples
///
/// ```
/// use dynomite::util::dyn_string::eq_ignore_ascii_case;
/// assert!(eq_ignore_ascii_case(b"GET", b"get"));
/// assert!(!eq_ignore_ascii_case(b"GET", b"GETS"));
/// ```