Line | Branch | Exec | Source |
---|---|---|---|
1 | /* GATE PROJECT LICENSE: | ||
2 | +----------------------------------------------------------------------------+ | ||
3 | | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> | | ||
4 | | All rights reserved. | | ||
5 | | | | ||
6 | | Redistribution and use in source and binary forms, with or without | | ||
7 | | modification, are permitted provided that the following conditions are met:| | ||
8 | | | | ||
9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
10 | | this list of conditions and the following disclaimer. | | ||
11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
12 | | notice, this list of conditions and the following disclaimer in the | | ||
13 | | documentation and/or other materials provided with the distribution. | | ||
14 | | | | ||
15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
26 | +----------------------------------------------------------------------------+ | ||
27 | */ | ||
28 | |||
29 | #include "gate/regexpressions.hpp" | ||
30 | #include "gate/exceptions.hpp" | ||
31 | #include "gate/memalloc.hpp" | ||
32 | |||
33 | namespace gate | ||
34 | { | ||
35 | 13 | RegEx::RegEx(String const& pattern) | |
36 | { | ||
37 | 13 | result_t result = gate_regex_create(&this->impl, pattern.c_impl()); | |
38 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | GATEXX_CHECK_ERROR(result); |
39 | 13 | } | |
40 | 2 | RegEx::RegEx(RegEx const& src) | |
41 | { | ||
42 | 2 | result_t result = gate_regex_clone(&this->impl, src.impl); | |
43 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_ERROR(result); |
44 | 2 | } | |
45 | 1 | RegEx& RegEx::operator=(RegEx const& src) | |
46 | { | ||
47 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | RegEx that(src); |
48 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | this->swap(that); |
49 | 2 | return *this; | |
50 | } | ||
51 | 30 | RegEx::~RegEx() | |
52 | { | ||
53 | 15 | gate_regex_release(this->impl); | |
54 | 15 | this->impl = NULL; | |
55 | 15 | } | |
56 | |||
57 | 1 | void RegEx::swap(RegEx& that) | |
58 | { | ||
59 | 1 | gate::swapRefs(this->impl, that.impl); | |
60 | 1 | } | |
61 | |||
62 | 15 | bool_t RegEx::match(String const& text, size_t& matchPosition, size_t& matchLength) | |
63 | { | ||
64 | 15 | gate_result_t ret = gate_regex_match(this->impl, text.c_impl(), &matchPosition, &matchLength); | |
65 | 15 | return GATE_SUCCEEDED(ret); | |
66 | } | ||
67 | |||
68 | |||
69 | 10 | index_t RegEx::match(String const& text, size_t* ptrMatchLength) | |
70 | { | ||
71 | 10 | size_t matchPosition = 0; | |
72 | 10 | size_t matchLength = 0; | |
73 |
3/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
✓ Branch 4 taken 1 times.
|
10 | if (this->match(text, matchPosition, matchLength)) |
74 | { | ||
75 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
|
9 | if (ptrMatchLength) |
76 | { | ||
77 | 7 | *ptrMatchLength = matchLength; | |
78 | } | ||
79 | 9 | return static_cast<index_t>(matchPosition); | |
80 | } | ||
81 | 1 | return -1; | |
82 | } | ||
83 | |||
84 | 1 | gate_regex_t RegEx::c_impl() | |
85 | { | ||
86 | 1 | return this->impl; | |
87 | } | ||
88 | |||
89 | } // end of namespace gate | ||
90 | |||
91 |