Upa URL C++ library
A WHATWG URL Standard implementation
main
Toggle main menu visibility
Loading...
Searching...
No Matches
regex_engine_srell.h
Go to the documentation of this file.
1
// Copyright 2025-2026 Rimas Misevičius
2
// Distributed under the BSD-style license that can be
3
// found in the LICENSE file.
4
//
5
#ifndef UPA_REGEX_ENGINE_SRELL_H
6
#define UPA_REGEX_ENGINE_SRELL_H
7
8
#if __has_include("srell/srell.hpp")
9
# include "srell/srell.hpp"
10
#else
11
# include "srell.hpp"
12
#endif
13
#include <cstddef>
14
#include <optional>
15
#include <string>
16
#include <string_view>
17
18
namespace
upa
{
19
31
class
regex_engine_srell
{
32
public
:
33
class
result
{
34
public
:
35
inline
std::size_t
size
()
const
{
36
return
arr_.size();
37
}
38
inline
std::optional<std::string>
get
(std::size_t ind, std::string_view)
const
{
39
const
auto
& res = arr_[ind];
40
if
(res.matched)
41
return
std::string{ res.first, res.second };
42
return
std::nullopt;
43
}
44
private
:
45
srell::match_results<std::string_view::const_iterator> arr_;
46
friend
class
regex_engine_srell
;
47
};
48
49
inline
bool
init
(std::string_view regex_str,
bool
ignore_case) {
50
// 4. If options's ignore case is true then set flags to "vi".
51
// 5. Otherwise set flags to "v"
52
const
auto
commonflags = srell::regex::ECMAScript | srell::regex::vmode |
53
srell::regex::quiet;
// do not throw a srell::regex_error on errors
54
const
auto
flag = ignore_case
55
? (commonflags | srell::regex::icase)
56
: commonflags;
57
return
re_.assign(regex_str.data(), regex_str.length(), flag).ecode() == 0;
58
}
59
60
inline
bool
exec
(std::string_view input,
result
& res)
const
{
61
return
srell::regex_match(input.begin(), input.end(), res.arr_, re_);
62
}
63
inline
bool
test
(std::string_view input)
const
{
64
return
srell::regex_match(input.begin(), input.end(), re_);
65
}
66
67
private
:
68
srell::regex re_;
69
};
70
71
}
// namespace upa
72
73
#endif
// UPA_REGEX_ENGINE_SRELL_H
upa::regex_engine_srell::result
Definition
regex_engine_srell.h:33
upa::regex_engine_srell::result::get
std::optional< std::string > get(std::size_t ind, std::string_view) const
Definition
regex_engine_srell.h:38
upa::regex_engine_srell::result::regex_engine_srell
friend class regex_engine_srell
Definition
regex_engine_srell.h:46
upa::regex_engine_srell::result::size
std::size_t size() const
Definition
regex_engine_srell.h:35
upa::regex_engine_srell
Regex engine class based on SRELL library.
Definition
regex_engine_srell.h:31
upa::regex_engine_srell::exec
bool exec(std::string_view input, result &res) const
Definition
regex_engine_srell.h:60
upa::regex_engine_srell::test
bool test(std::string_view input) const
Definition
regex_engine_srell.h:63
upa::regex_engine_srell::init
bool init(std::string_view regex_str, bool ignore_case)
Definition
regex_engine_srell.h:49
upa
Definition
url.h:50
include
upa
regex_engine_srell.h
Generated by
1.18.0