Return the byte positions (relative to the start of `sql`) of every occurrence of `op` that falls inside a `Text` segment.
(sql: &str, op: &str)
| 234 | /// Return the byte positions (relative to the start of `sql`) of every |
| 235 | /// occurrence of `op` that falls inside a `Text` segment. |
| 236 | pub fn find_operator_positions(sql: &str, op: &str) -> Vec<usize> { |
| 237 | let mut positions = Vec::new(); |
| 238 | for seg in segments(sql) { |
| 239 | if let SqlSegment::Text(t) = seg { |
| 240 | // Safety: `t` is a sub-slice of `sql`; pointer arithmetic is valid. |
| 241 | let base = t.as_ptr() as usize - sql.as_ptr() as usize; |
| 242 | let mut search_from = 0; |
| 243 | while let Some(rel) = t[search_from..].find(op) { |
| 244 | let abs = base + search_from + rel; |
| 245 | positions.push(abs); |
| 246 | search_from += rel + op.len(); |
| 247 | } |
| 248 | } |
| 249 | } |
| 250 | positions |
| 251 | } |
| 252 | |
| 253 | /// Return `true` if `{` appears inside any `Text` segment of `sql`. |
| 254 | pub fn has_brace_outside_literals(sql: &str) -> bool { |