From 006471b2e2f05a4409cd9ae86c94efa5fda49518 Mon Sep 17 00:00:00 2001 From: pr4ku3p2c <925473174@qq.com> Date: Mon, 20 Jan 2025 18:07:18 +0800 Subject: [PATCH] ADD file via upload --- highlighter.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 highlighter.h diff --git a/highlighter.h b/highlighter.h new file mode 100644 index 0000000..4018894 --- /dev/null +++ b/highlighter.h @@ -0,0 +1,29 @@ +#pragma once +#include +#include + +class Highlighter { +public: + struct HighlightSpan { + size_t start; + size_t length; + }; + + static std::string highlight_text( + const std::string& text, + const std::vector& keywords, + const std::string& pre_tag = "", + const std::string& post_tag = "" + ); + + static std::vector find_keyword_positions( + const std::string& text, + const std::vector& keywords + ); + + static std::string extract_snippet( + const std::string& text, + const std::vector& spans, + size_t context_size = 50 + ); +}; \ No newline at end of file