56 lines
1.6 KiB
C++
56 lines
1.6 KiB
C++
/* This file is part of epubgrep.
|
|
* Copyright © 2021 tastytea <tastytea@tastytea.de>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
* the Free Software Foundation, version 3.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU Affero General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef EPUBGREP_SEARCH_HPP
|
|
#define EPUBGREP_SEARCH_HPP
|
|
|
|
#include "fs-compat.hpp"
|
|
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
namespace epubgrep::search
|
|
{
|
|
|
|
using match_context = std::pair<std::string, std::string>;
|
|
|
|
struct match
|
|
{
|
|
std::string text; //!< Matched string.
|
|
match_context context; //!< The context around the match.
|
|
std::string filepath; //!< The file path of the matched line.
|
|
std::string headline; //!< The last headline, if available.
|
|
std::string page; //!< The page number, if available.
|
|
};
|
|
|
|
struct options
|
|
{
|
|
// TODO: regex type
|
|
bool ignore_case{false};
|
|
bool nostrip{false};
|
|
std::uint64_t context{0};
|
|
};
|
|
|
|
std::vector<match> search(const fs::path &filepath, std::string_view regex,
|
|
const options &opts);
|
|
|
|
} // namespace epubgrep::search
|
|
|
|
#endif // EPUBGREP_SEARCH_HPP
|