Skip to main content

Module fieldpath

Module fieldpath 

Source
Expand description

Field-path helpers shared by the parser, evaluator, and converters.

Array selectors ([any], [all], [N], …) are written in brackets on a field path. To keep a literal bracket expressible in a field name, a literal [ or ] is escaped as \[ / \] (mirroring Sigma’s \* / \? wildcard escaping). Only an unescaped bracket opens a selector; an escaped one is a literal part of the field name and is unescaped before the field is resolved.

Functions§

ends_with_unescaped
Whether s ends with the ASCII byte ch and that byte is not escaped.
escape_brackets
Escape every unescaped [ and ] as \[ / \], leaving already-escaped brackets and every other character untouched. The inverse of unescape_brackets. Used to render a field name whose brackets must be read literally (for example below the array-matching spec version), so the escape-aware field resolver does not treat a trailing [...] as a selector. Returns a borrow when there is nothing to escape (the common case).
first_unescaped
Index of the first occurrence of the ASCII byte ch that is not escaped by an immediately preceding backslash. ch must be ASCII ([ or ] here); scanning bytes is safe because those never appear inside a UTF-8 multibyte sequence.
unescape_brackets
Unescape \[ and \] into literal [ and ]. Any other backslash is left untouched. Returns a borrow when there is nothing to unescape (the common case), so non-escaped field names never allocate.