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

Function read_string_literal

nodedb/src/control/planner/procedural/tokenizer.rs:225–246  ·  view source on GitHub ↗

Read a single-quoted string literal, handling escaped quotes ('').

(input: &str, start: usize)

Source from the content-addressed store, hash-verified

223
224/// Read a single-quoted string literal, handling escaped quotes ('').
225fn read_string_literal(input: &str, start: usize) -> Result<(String, usize), ProceduralError> {
226 let bytes = input.as_bytes();
227 let mut i = start + 1; // skip opening quote
228 let mut result = String::new();
229
230 while i < bytes.len() {
231 if bytes[i] == b'\'' {
232 // Check for escaped quote ('').
233 if i + 1 < bytes.len() && bytes[i + 1] == b'\'' {
234 result.push('\'');
235 i += 2;
236 } else {
237 // End of string literal.
238 return Ok((result, i + 1));
239 }
240 } else {
241 result.push(bytes[i] as char);
242 i += 1;
243 }
244 }
245 Err(ProceduralError::tokenize("unterminated string literal"))
246}
247
248/// Check if the current word + next word form a two-word keyword.
249/// Returns (keyword, position_after_second_word) if matched.

Callers 1

tokenizeFunction · 0.85

Calls 4

tokenizeFunction · 0.70
as_bytesMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected