Upa URL C++ library
A WHATWG URL Standard implementation
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
18namespace upa {
19
32public:
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
67private:
68 srell::regex re_;
69};
70
71} // namespace upa
72
73#endif // UPA_REGEX_ENGINE_SRELL_H
std::optional< std::string > get(std::size_t ind, std::string_view) const
Regex engine class based on SRELL library.
bool exec(std::string_view input, result &res) const
bool test(std::string_view input) const
bool init(std::string_view regex_str, bool ignore_case)
Definition url.h:50