Split a string on the PHP `.` concatenation operator, respecting string literal boundaries.
(text: &str)
| 176 | /// Split a string on the PHP `.` concatenation operator, respecting |
| 177 | /// string literal boundaries. |
| 178 | fn split_concat_parts(text: &str) -> Vec<&str> { |
| 179 | let mut parts = Vec::new(); |
| 180 | let bytes = text.as_bytes(); |
| 181 | let mut start = 0; |
| 182 | let mut i = 0; |
| 183 | let mut in_single = false; |
| 184 | let mut in_double = false; |
| 185 | |
| 186 | while i < bytes.len() { |
| 187 | match bytes[i] { |
| 188 | b'\'' if !in_double => in_single = !in_single, |
| 189 | b'"' if !in_single => in_double = !in_double, |
| 190 | b'.' if !in_single && !in_double => { |
| 191 | parts.push(&text[start..i]); |
| 192 | start = i + 1; |
| 193 | } |
| 194 | _ => {} |
| 195 | } |
| 196 | i += 1; |
| 197 | } |
| 198 | parts.push(&text[start..]); |
| 199 | parts |
| 200 | } |
| 201 | |
| 202 | // ─── Name generation ──────────────────────────────────────────────────────── |
| 203 |
no test coverage detected