• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #853

19 Dec 2022 01:01AM UTC coverage: 86.287% (+0.4%) from 85.912%
#853

push

StellarBot
Merge #6109

6109: Modernize serialization module r=hkaiser a=hkaiser

- flyby separate serialization of Boost types

working towards https://github.com/STEllAR-GROUP/hpx/issues/5497

Co-authored-by: Hartmut Kaiser <hartmut.kaiser@gmail.com>

53 of 53 new or added lines in 6 files covered. (100.0%)

173939 of 201582 relevant lines covered (86.29%)

1931657.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/core/util/src/regex_from_pattern.cpp
1
//  Copyright (c) 2007-2017 Hartmut Kaiser
2
//
3
//  SPDX-License-Identifier: BSL-1.0
4
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
5
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6

7
#include <hpx/config.hpp>
8
#include <hpx/modules/errors.hpp>
9
#include <hpx/util/regex_from_pattern.hpp>
10

11
#include <string>
12

13
namespace hpx { namespace util {
14
    namespace detail {
15
        ///////////////////////////////////////////////////////////////////////
16
        inline std::string regex_from_character_set(
×
17
            std::string::const_iterator& it, std::string::const_iterator end,
18
            error_code& ec)
19
        {
20
            std::string::const_iterator start = it;
×
21
            std::string result(1, *it);    // copy '['
×
22
            if (*++it == '!')
×
23
            {
24
                result.append(1, '^');    // negated character set
×
25
            }
×
26
            else if (*it == ']')
×
27
            {
28
                HPX_THROWS_IF(ec, hpx::error::bad_parameter,
×
29
                    "regex_from_character_set",
30
                    "Invalid pattern (empty character set) at: " +
31
                        std::string(start, end));
32
                return "";
×
33
            }
34
            else
35
            {
36
                result.append(1, *it);    // append this character
×
37
            }
38

39
            // copy while in character set
40
            while (++it != end)
×
41
            {
42
                result.append(1, *it);
×
43
                if (*it == ']')
×
44
                    break;
×
45
            }
46

47
            if (it == end || *it != ']')
×
48
            {
49
                HPX_THROWS_IF(ec, hpx::error::bad_parameter,
×
50
                    "regex_from_character_set",
51
                    "Invalid pattern (missing closing ']') at: " +
52
                        std::string(start, end));
53
                return "";
×
54
            }
55

56
            return result;
×
57
        }
×
58
    }    // namespace detail
59

60
    std::string regex_from_pattern(std::string const& pattern, error_code& ec)
×
61
    {
62
        std::string result;
×
63
        std::string::const_iterator end = pattern.end();
×
64
        for (std::string::const_iterator it = pattern.begin(); it != end; ++it)
×
65
        {
66
            char c = *it;
×
67
            switch (c)
×
68
            {
69
            case '*':
70
                result.append(".*");
×
71
                break;
×
72

73
            case '?':
74
                result.append(1, '.');
×
75
                break;
×
76

77
            case '[':
78
            {
79
                std::string r = detail::regex_from_character_set(it, end, ec);
×
80
                if (ec)
×
81
                    return "";
×
82
                result.append(r);
×
83
            }
×
84
            break;
×
85

86
            case '\\':
87
                if (++it == end)
×
88
                {
89
                    HPX_THROWS_IF(ec, hpx::error::bad_parameter,
×
90
                        "regex_from_pattern",
91
                        "Invalid escape sequence at: " + pattern);
92
                    return "";
×
93
                }
94
                result.append(1, *it);
×
95
                break;
×
96

97
            // escape regex special characters
98
            // NOLINTNEXTLINE(bugprone-branch-clone)
99
            case '+':
100
                [[fallthrough]];
101
            case '.':
102
                [[fallthrough]];
103
            case '(':
104
                [[fallthrough]];
105
            case ')':
106
                [[fallthrough]];
107
            case '{':
108
                [[fallthrough]];
109
            case '}':
110
                [[fallthrough]];
111
            case '^':
112
                [[fallthrough]];
113
            case '$':
114
                result.append("\\");
×
115
                [[fallthrough]];
116

117
            default:
118
                result.append(1, c);
×
119
                break;
×
120
            }
121
        }
×
122
        return result;
×
123
    }
×
124
}}    // namespace hpx::util
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc