Skip to content
Myr

mod.rs

This file

Path

crates/core/flags/doc/mod.rs

38 lines · 1.2 KiB · Rust

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 5f5da48 point at it.

globset: support nested alternatesLuke Sandbergbefore adoption5f5da48

lines 1–38why, one step back
1/*!
2Modules for generating documentation for ripgrep's flags.3*/45pub(crate) mod help;6pub(crate) mod man;7pub(crate) mod version;89/// Searches for `\tag{...}` occurrences in `doc` and calls `replacement` for10/// each such tag found.11///12/// The first argument given to `replacement` is the tag value, `...`. The13/// second argument is the buffer that accumulates the full replacement text.14///15/// Since this function is only intended to be used on doc strings written into16/// the program source code, callers should panic in `replacement` if there are17/// any errors or unexpected circumstances.18fn render_custom_markup(19 mut doc: &str,20 tag: &str,21 mut replacement: impl FnMut(&str, &mut String),22) -> String {23 let mut out = String::with_capacity(doc.len());24 let tag_prefix = format!(r"\{tag}{{");25 while let Some(offset) = doc.find(&tag_prefix) {26 out.push_str(&doc[..offset]);2728 let start = offset + tag_prefix.len();29 let Some(end) = doc[start..].find('}').map(|i| start + i) else {30 unreachable!(r"found {tag_prefix} without closing }}");31 };32 let name = &doc[start..end];33 replacement(name, &mut out);34 doc = &doc[end + 1..];35 }36 out.push_str(doc);37 out38}