FOSSredder 0.5.0
Loading...
Searching...
No Matches
ParserDateUtils.cpp
Go to the documentation of this file.
1
5
7
8
9#include <regex>
10
11namespace {
12
13const std::regex gShortDateRegex(R"(\b\d{2}\.\s*\d{2}\b)");
14const std::regex gFullDateRegex(R"((\d{2}\.\d{2}\.\d{4}))");
15
16}
17
19
20bool hasShortDateToken(const std::string& text) noexcept
21{
22 try {
23 return std::regex_search(text, gShortDateRegex);
24 } catch (...) {
25 return false;
26 }
27}
28
29bool containsShortDate(const std::string& text) noexcept
30{
31 return hasShortDateToken(text);
32}
33
34std::optional<std::string> findFirstFullDate(const std::string& text) noexcept
35{
36 try {
37 std::smatch match;
38 if (std::regex_search(text, match, gFullDateRegex)) return match.str(1);
39 } catch (...) {}
40 return std::nullopt;
41}
42
43}
Declares date-detection helpers for the import parser.
bool containsShortDate(const std::string &text) noexcept
Checks whether the text contains any short date pattern.
std::optional< std::string > findFirstFullDate(const std::string &text) noexcept
Finds the first full date in a text fragment.
bool hasShortDateToken(const std::string &text) noexcept
Checks whether the text contains a short date token.