You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
736 B
29 lines
736 B
#pragma once
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class Highlighter {
|
|
public:
|
|
struct HighlightSpan {
|
|
size_t start;
|
|
size_t length;
|
|
};
|
|
|
|
static std::string highlight_text(
|
|
const std::string& text,
|
|
const std::vector<std::string>& keywords,
|
|
const std::string& pre_tag = "<em>",
|
|
const std::string& post_tag = "</em>"
|
|
);
|
|
|
|
static std::vector<HighlightSpan> find_keyword_positions(
|
|
const std::string& text,
|
|
const std::vector<std::string>& keywords
|
|
);
|
|
|
|
static std::string extract_snippet(
|
|
const std::string& text,
|
|
const std::vector<HighlightSpan>& spans,
|
|
size_t context_size = 50
|
|
);
|
|
};
|