Add skeleton for search::search().

- Type for matches
- Type for options.
This commit is contained in:
tastytea 2021-05-24 07:52:36 +02:00
parent 78230b26e6
commit 1f82d9927a
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 88 additions and 0 deletions

33
src/search.cpp Normal file
View File

@ -0,0 +1,33 @@
/* 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/>.
*/
#include "search.hpp"
#include "fs-compat.hpp"
#include <string_view>
#include <vector>
namespace epubgrep::search
{
std::vector<match> search(const fs::path &filepath, std::string_view regex,
const options &opts)
{
return {};
}
} // namespace epubgrep::search

55
src/search.hpp Normal file
View File

@ -0,0 +1,55 @@
/* 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