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

STEllAR-GROUP / hpx / #855

20 Dec 2022 09:59PM UTC coverage: 86.55% (+0.04%) from 86.511%
#855

push

StellarBot
Merge #6112

6112: Modernize modules from levels 9 and 10 r=hkaiser a=hkaiser

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

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

185 of 185 new or added lines in 30 files covered. (100.0%)

174495 of 201611 relevant lines covered (86.55%)

1898061.31 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::util {
14

15
    namespace detail {
16

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

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

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

58
            return result;
×
59
        }
×
60
    }    // namespace detail
61

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

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

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

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

99
            // escape regex special characters
100
            // NOLINTNEXTLINE(bugprone-branch-clone)
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
                [[fallthrough]];
115
            case '$':
116
                result.append("\\");
×
117
                [[fallthrough]];
118

119
            default:
120
                result.append(1, c);
×
121
                break;
×
122
            }
123
        }
×
124
        return result;
×
125
    }
×
126
}    // 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