pub fn locate_value_span(
content: &str,
search_from: usize,
value: &str,
) -> Option<(usize, usize)>Expand description
Finds the byte offset in content (searching only within the line starting at
search_from) where the literal bytes of value occur.
The scanner-reported marker usually points exactly at the value’s start for a plain
scalar, but may point at the opening quote for a quoted one — rather than
reverse-engineering yaml-rust2’s exact escaping/quoting byte accounting, this verifies
the direct-offset guess first and falls back to a bounded same-line search (see
MAX_FALLBACK_SCAN_BYTES), which is exact for the unescaped ASCII text most manifest
values are.
§Examples
use deps_core::lsp_helpers::locate_value_span;
let content = "prefix xxxxx actions/checkout@v4 suffix";
let (start, end) = locate_value_span(content, 0, "actions/checkout@v4").unwrap();
assert_eq!(&content[start..end], "actions/checkout@v4");