Extract the right operand after `<->`: ARRAY[...], $param, or identifier. Returns (operand_text, consumed_length).
(after: &str)
| 49 | /// Extract the right operand after `<->`: ARRAY[...], $param, or identifier. |
| 50 | /// Returns (operand_text, consumed_length). |
| 51 | fn extract_right_operand(after: &str) -> Option<(String, usize)> { |
| 52 | let trimmed = after.trim_start(); |
| 53 | let upper = trimmed.to_uppercase(); |
| 54 | |
| 55 | if upper.starts_with("ARRAY[") { |
| 56 | let mut depth = 0; |
| 57 | for (i, c) in trimmed.char_indices() { |
| 58 | match c { |
| 59 | '[' => depth += 1, |
| 60 | ']' => { |
| 61 | depth -= 1; |
| 62 | if depth == 0 { |
| 63 | return Some((trimmed[..=i].to_string(), i + 1)); |
| 64 | } |
| 65 | } |
| 66 | _ => {} |
| 67 | } |
| 68 | } |
| 69 | None |
| 70 | } else if trimmed.starts_with('$') { |
| 71 | let end = trimmed |
| 72 | .find(|c: char| !c.is_ascii_alphanumeric() && c != '_' && c != '$') |
| 73 | .unwrap_or(trimmed.len()); |
| 74 | Some((trimmed[..end].to_string(), end)) |
| 75 | } else { |
| 76 | let end = trimmed |
| 77 | .find(|c: char| !c.is_ascii_alphanumeric() && c != '_' && c != '.') |
| 78 | .unwrap_or(trimmed.len()); |
| 79 | if end == 0 { |
| 80 | return None; |
| 81 | } |
| 82 | Some((trimmed[..end].to_string(), end)) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /// Rewrite all occurrences of `expr <=> expr` to `vector_cosine_distance(expr, expr)`. |
| 87 | /// |
no test coverage detected