#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/query_parser/snippet.h"
#include <stdint.h>
#include <algorithm>
#include <memory>
#include "base/check.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "third_party/icu/source/common/unicode/brkiter.h"
#include "third_party/icu/source/common/unicode/utext.h"
#include "third_party/icu/source/common/unicode/utf8.h"
namespace query_parser {
namespace {
bool PairFirstLessThan(const Snippet::MatchPosition& a,
const Snippet::MatchPosition& b) { … }
void CoalescePositionsFrom(size_t offset,
Snippet::MatchPositions* match_positions) { … }
void AddMatch(size_t start,
size_t end,
Snippet::MatchPositions* match_positions) { … }
size_t AdvanceAndReturnUTF16Pos(const char* utf8_string,
int32_t utf8_length,
int32_t offset,
int32_t* utf8_pos,
size_t* utf16_pos) { … }
void MoveByNGraphemes(icu::BreakIterator* bi, int count, size_t* utf8_pos) { … }
const int kSnippetContext = …;
bool IsNextMatchWithinSnippetWindow(icu::BreakIterator* bi,
size_t previous_match_end,
size_t next_match_start) { … }
}
void Snippet::ExtractMatchPositions(const std::string& offsets_str,
const std::string& column_num,
MatchPositions* match_positions) { … }
void Snippet::ConvertMatchPositionsToWide(
const std::string& utf8_string,
Snippet::MatchPositions* match_positions) { … }
Snippet::Snippet() { … }
Snippet::Snippet(const Snippet& other) = default;
Snippet::Snippet(Snippet&& other) noexcept = default;
Snippet::~Snippet() { … }
Snippet& Snippet::operator=(const Snippet&) = default;
void Snippet::ComputeSnippet(const MatchPositions& match_positions,
const std::string& document) { … }
void Snippet::Swap(Snippet* other) { … }
}