1#![cfg_attr(not(feature = "std"), no_std)]
61#![cfg_attr(docsrs, feature(doc_cfg))]
62
63#[cfg(feature = "alloc")]
68extern crate alloc;
69
70mod ends_with_ignore_ascii_case;
71mod ends_with_ignore_ascii_case_multiple;
72#[cfg(feature = "alloc")]
73mod ends_with_ignore_case;
74mod ends_with_multiple;
75mod eq_ignore_ascii_case;
76mod eq_ignore_ascii_case_multiple;
77#[cfg(feature = "unicase")]
78mod eq_ignore_case;
79mod eq_multiple;
80#[cfg(feature = "alloc")]
81mod escape_characters;
82mod is_ascii_lowercased;
83mod is_ascii_uppercased;
84mod is_lowercased;
85mod is_uppercased;
86#[cfg(feature = "alloc")]
87mod remove_all_invisible_characters;
88#[cfg(feature = "alloc")]
89mod replace_newlines_with_space;
90mod starts_with_ignore_ascii_case;
91mod starts_with_ignore_ascii_case_multiple;
92#[cfg(feature = "alloc")]
93mod starts_with_ignore_case;
94mod starts_with_multiple;
95#[cfg(feature = "alloc")]
96mod to_lowercase;
97#[cfg(feature = "alloc")]
98mod to_uppercase;
99#[cfg(feature = "alloc")]
100mod trim;
101
102pub use ends_with_ignore_ascii_case::*;
103pub use ends_with_ignore_ascii_case_multiple::*;
104#[cfg(feature = "alloc")]
105pub use ends_with_ignore_case::*;
106pub use ends_with_multiple::*;
107pub use eq_ignore_ascii_case::*;
108pub use eq_ignore_ascii_case_multiple::*;
109#[cfg(feature = "unicase")]
110pub use eq_ignore_case::*;
111pub use eq_multiple::*;
112#[cfg(feature = "alloc")]
113pub use escape_characters::*;
114pub use is_ascii_lowercased::*;
115pub use is_ascii_uppercased::*;
116pub use is_lowercased::*;
117pub use is_uppercased::*;
118#[cfg(feature = "alloc")]
119pub use remove_all_invisible_characters::*;
120#[cfg(feature = "alloc")]
121pub use replace_newlines_with_space::*;
122pub use starts_with_ignore_ascii_case::*;
123pub use starts_with_ignore_ascii_case_multiple::*;
124#[cfg(feature = "alloc")]
125pub use starts_with_ignore_case::*;
126pub use starts_with_multiple::*;
127#[cfg(feature = "alloc")]
128pub use to_lowercase::*;
129#[cfg(feature = "alloc")]
130pub use to_uppercase::*;
131#[cfg(feature = "alloc")]
132pub use trim::*;
133
134#[cfg(feature = "alloc")]
135pub(crate) unsafe fn find_substring_position(parent: &str, sub: &str) -> (usize, usize) {
136 let parent_start_address = parent.as_ptr() as usize;
137
138 let sub_start_address = sub.as_ptr() as usize;
139 let position_len = sub.len();
140
141 let position_start = sub_start_address - parent_start_address;
142
143 (position_start, position_len)
144}
145
146#[cfg(feature = "alloc")]
147pub(crate) unsafe fn into_substring_in_place(
148 mut s: String,
149 (start, len): (usize, usize),
150) -> String {
151 let bytes = s.as_mut_vec();
152
153 bytes.drain(..start);
154 bytes.truncate(len);
155
156 s
157}
158
159#[cfg(feature = "alloc")]
160macro_rules! to_substring_in_place {
161 ($parent:ident, $sub:ident) => {{
162 let position = $crate::find_substring_position($parent.as_str(), $sub);
163
164 $crate::into_substring_in_place($parent, position)
165 }};
166}
167
168#[cfg(feature = "alloc")]
169pub(crate) use to_substring_in_place;