/
githubmirror
/
ripgrep
Обзор
Документация
Войти
/
githubmirror
/
ripgrep
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
crates/core/flags/doc/mod.rs
38 строк
1 KB
Andrew Gallant
cli: replace clap with lexopt and supporting code
21 ноя 2023, 07:51
21 ноя 2023, 07:51
082245d
Код
Авторство
О чём код?
/*! Modules for generating documentation for ripgrep's flags. */ pub(crate) mod help; pub(crate) mod man; pub(crate) mod version; /// Searches for `\tag{...}` occurrences in `doc` and calls `replacement` for /// each such tag found. /// /// The first argument given to `replacement` is the tag value, `...`. The /// second argument is the buffer that accumulates the full replacement text. /// /// Since this function is only intended to be used on doc strings written into /// the program source code, callers should panic in `replacement` if there are /// any errors or unexpected circumstances. fn render_custom_markup( mut doc: &str, tag: &str, mut replacement: impl FnMut(&str, &mut String), ) -> String { let mut out = String::with_capacity(doc.len()); let tag_prefix = format!(r"\{tag}{{"); while let Some(offset) = doc.find(&tag_prefix) { out.push_str(&doc[..offset]); let start = offset + tag_prefix.len(); let Some(end) = doc[start..].find('}').map(|i| start + i) else { unreachable!(r"found {tag_prefix} without closing }}"); }; let name = &doc[start..end]; replacement(name, &mut out); doc = &doc[end + 1..]; } out.push_str(doc); out }