diff options
author | vvvv <[email protected]> | 2025-10-06 11:26:09 +0300 |
---|---|---|
committer | vvvv <[email protected]> | 2025-10-06 11:53:26 +0300 |
commit | 60f45e69a4d7dbc6131208e16c45faf35aa5a985 (patch) | |
tree | 4daa45b52c295a178c7620e4c93921465fcf7950 /yql/essentials/utils/docs/link_page.cpp | |
parent | 1bded1a65a7e6e9171418f3e1c691d390125b64e (diff) |
YQL-20086 utils
init
commit_hash:54feccd520ebd0ab23612bc0cb830914dff9d0e8
Diffstat (limited to 'yql/essentials/utils/docs/link_page.cpp')
-rw-r--r-- | yql/essentials/utils/docs/link_page.cpp | 168 |
1 files changed, 84 insertions, 84 deletions
diff --git a/yql/essentials/utils/docs/link_page.cpp b/yql/essentials/utils/docs/link_page.cpp index eb71979462d..985410fafd5 100644 --- a/yql/essentials/utils/docs/link_page.cpp +++ b/yql/essentials/utils/docs/link_page.cpp @@ -7,110 +7,110 @@ namespace NYql::NDocs { - TMaybe<TString> MatchSingleFunctionHeader(TStringBuf header) { - return NormalizedName(TString(header)); +TMaybe<TString> MatchSingleFunctionHeader(TStringBuf header) { + return NormalizedName(TString(header)); +} + +TVector<TString> SplitBy(TStringBuf delim, const TVector<TString>& strings) { + TVector<TString> parts; + for (const TString& s : strings) { + StringSplitter(s).SplitByString(delim).AddTo(&parts); } - - TVector<TString> SplitBy(TStringBuf delim, const TVector<TString>& strings) { - TVector<TString> parts; - for (const TString& s : strings) { - StringSplitter(s).SplitByString(delim).AddTo(&parts); + return parts; +} + +TVector<TString> SplitByPunctuation(TStringBuf header) { + TVector<TString> parts = {TString(header)}; + parts = SplitBy(" и ", parts); + parts = SplitBy(" / ", parts); + parts = SplitBy(", ", parts); + return parts; +} + +TVector<TString> MatchMultiFunctionHeader(TStringBuf header) { + TVector<TString> names = SplitByPunctuation(header); + + for (TString& name : names) { + TMaybe<TString> normalized = NormalizedName(std::move(name)); + if (!normalized) { + return {}; } - return parts; - } - TVector<TString> SplitByPunctuation(TStringBuf header) { - TVector<TString> parts = {TString(header)}; - parts = SplitBy(" и ", parts); - parts = SplitBy(" / ", parts); - parts = SplitBy(", ", parts); - return parts; + name = std::move(*normalized); } - TVector<TString> MatchMultiFunctionHeader(TStringBuf header) { - TVector<TString> names = SplitByPunctuation(header); - - for (TString& name : names) { - TMaybe<TString> normalized = NormalizedName(std::move(name)); - if (!normalized) { - return {}; - } - - name = std::move(*normalized); - } + return names; +} - return names; +TVector<TString> ExtractNormalized(TStringBuf header) { + if (auto single = MatchSingleFunctionHeader(header)) { + return {*single}; } - - TVector<TString> ExtractNormalized(TStringBuf header) { - if (auto single = MatchSingleFunctionHeader(header)) { - return {*single}; - } - if (auto multi = MatchMultiFunctionHeader(header)) { - return multi; - } - return {}; + if (auto multi = MatchMultiFunctionHeader(header)) { + return multi; } - - void EnrichFromMarkdown(TLinks& links, const TString& path, const TMarkdownHeader& header) { - for (const TString& name : ExtractNormalized(header.Content)) { - links[name] = { - .RelativePath = path, - .Anchor = header.Anchor, - }; - } + return {}; +} + +void EnrichFromMarkdown(TLinks& links, const TString& path, const TMarkdownHeader& header) { + for (const TString& name : ExtractNormalized(header.Content)) { + links[name] = { + .RelativePath = path, + .Anchor = header.Anchor, + }; } +} - void EnrichFromMarkdown(TLinks& links, const TString& path, const TMarkdownPage& page) { - for (const auto& [anchor, section] : page.SectionsByAnchor) { - const TMarkdownHeader& header = section.Header; - EnrichFromMarkdown(links, path, header); - } +void EnrichFromMarkdown(TLinks& links, const TString& path, const TMarkdownPage& page) { + for (const auto& [anchor, section] : page.SectionsByAnchor) { + const TMarkdownHeader& header = section.Header; + EnrichFromMarkdown(links, path, header); } +} - void EnrichFromMarkdown(TLinks& links, const TPages& pages) { - for (const auto& [path, page] : pages) { - EnrichFromMarkdown(links, path, page); - } +void EnrichFromMarkdown(TLinks& links, const TPages& pages) { + for (const auto& [path, page] : pages) { + EnrichFromMarkdown(links, path, page); } - - TLinks GetLinksFromPages(const TPages& pages) { - TLinks links; - EnrichFromMarkdown(links, pages); - return links; +} + +TLinks GetLinksFromPages(const TPages& pages) { + TLinks links; + EnrichFromMarkdown(links, pages); + return links; +} + +TPages Stripped(TPages&& pages, const TLinks& links) { + THashSet<TString> usedPaths; + THashMap<TString, THashSet<TString>> usedAnchors; + for (const auto& [_, link] : links) { + TString anchor = link.Anchor.GetOrElse(""); + usedAnchors[link.RelativePath].emplace(std::move(anchor)); } - TPages Stripped(TPages&& pages, const TLinks& links) { - THashSet<TString> usedPaths; - THashMap<TString, THashSet<TString>> usedAnchors; - for (const auto& [_, link] : links) { - TString anchor = link.Anchor.GetOrElse(""); - usedAnchors[link.RelativePath].emplace(std::move(anchor)); - } - - THashSet<TString> unusedPaths; - THashMap<TString, THashSet<TString>> unusedAnchors; - for (const auto& [path, page] : pages) { - for (const auto& [anchor, _] : page.SectionsByAnchor) { - if (!usedAnchors.contains(path)) { - unusedPaths.emplace(path); - } else if (!usedAnchors[path].contains(anchor)) { - unusedAnchors[path].emplace(anchor); - } - } - } - - for (const auto& [path, anchors] : unusedAnchors) { - for (const auto& anchor : anchors) { - pages[path].SectionsByAnchor.erase(anchor); + THashSet<TString> unusedPaths; + THashMap<TString, THashSet<TString>> unusedAnchors; + for (const auto& [path, page] : pages) { + for (const auto& [anchor, _] : page.SectionsByAnchor) { + if (!usedAnchors.contains(path)) { + unusedPaths.emplace(path); + } else if (!usedAnchors[path].contains(anchor)) { + unusedAnchors[path].emplace(anchor); } } + } - for (const auto& path : unusedPaths) { - pages.erase(path); + for (const auto& [path, anchors] : unusedAnchors) { + for (const auto& anchor : anchors) { + pages[path].SectionsByAnchor.erase(anchor); } + } - return pages; + for (const auto& path : unusedPaths) { + pages.erase(path); } + return pages; +} + } // namespace NYql::NDocs |