Split a parameter string on commas, respecting nested `()`, `<>`, `[]`, and `{}` delimiters. Returns borrowed slices into the input string.
(params_str: &str)
| 52 | /// |
| 53 | /// Returns borrowed slices into the input string. |
| 54 | pub(super) fn split_params(params_str: &str) -> Vec<&str> { |
| 55 | let mut result = Vec::new(); |
| 56 | let mut depth = 0i32; |
| 57 | let mut start = 0; |
| 58 | let bytes = params_str.as_bytes(); |
| 59 | |
| 60 | for (i, &b) in bytes.iter().enumerate() { |
| 61 | match b { |
| 62 | b'(' | b'<' | b'[' | b'{' => depth += 1, |
| 63 | b')' | b'>' | b']' | b'}' => depth -= 1, |
| 64 | b',' if depth == 0 => { |
| 65 | result.push(¶ms_str[start..i]); |
| 66 | start = i + 1; |
| 67 | } |
| 68 | _ => {} |
| 69 | } |
| 70 | } |
| 71 | result.push(¶ms_str[start..]); |
| 72 | result |
| 73 | } |
no test coverage detected