MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / find_operator_positions

Function find_operator_positions

nodedb-sql/src/parser/preprocess/lex.rs:236–251  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

234/// Return the byte positions (relative to the start of `sql`) of every
235/// occurrence of `op` that falls inside a `Text` segment.
236pub 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`.
254pub fn has_brace_outside_literals(sql: &str) -> bool {

Callers 1

rewrite_binary_opFunction · 0.85

Calls 5

segmentsFunction · 0.85
as_ptrMethod · 0.45
findMethod · 0.45
pushMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected