micro-test-plus
5.0.1
µTest++ Testing Framework
Toggle main menu visibility
Loading...
Searching...
No Matches
utility.cpp
Go to the documentation of this file.
1
/*
2
* This file is part of the µOS++ project (https://micro-os-plus.github.io/).
3
* Copyright (c) 2021-2026 Liviu Ionescu. All rights reserved.
4
*
5
* Permission to use, copy, modify, and/or distribute this software for any
6
* purpose is hereby granted, under the terms of the MIT license.
7
*
8
* If a copy of the license was not distributed with this file, it can be
9
* obtained from https://opensource.org/licenses/mit.
10
*
11
* Major parts of the code are inspired from v1.1.8 of the Boost UT project,
12
* released under the terms of the Boost Version 1.0 Software License,
13
* which can be obtained from https://www.boost.org/LICENSE_1_0.txt.
14
*/
15
16
// ----------------------------------------------------------------------------
17
34
35
// ----------------------------------------------------------------------------
36
37
#include "
micro-os-plus/micro-test-plus/utility.h
"
38
39
// ----------------------------------------------------------------------------
40
41
#if defined(__GNUC__)
42
#pragma GCC diagnostic ignored "-Waggregate-return"
43
#if defined(__clang__)
44
#pragma clang diagnostic ignored "-Wc++98-compat"
45
#endif
// defined(__clang__)
46
#endif
// defined(__GNUC__)
47
48
// ============================================================================
49
50
#if defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_ENABLED)
51
52
// ----------------------------------------------------------------------------
53
54
namespace
micro_os_plus::micro_test_plus
55
{
56
// --------------------------------------------------------------------------
57
58
namespace
utility
59
{
60
#if defined(__GNUC__)
61
#pragma GCC diagnostic push
62
63
#if defined(__clang__)
64
#pragma clang diagnostic ignored "-Wdocumentation"
65
#endif
// defined(__clang__)
66
#endif
// defined(__GNUC__)
67
86
[[nodiscard]]
const
char
*
87
extract_file_name
(
const
char
* path)
noexcept
88
{
89
const
std::string_view sv{ path };
90
const
auto
pos = sv.find_last_of (
"/\\"
);
91
if
(pos == std::string_view::npos)
92
{
93
return
path;
// No separators found, return original string.
94
}
95
return
sv.substr (pos + 1).data ();
96
}
97
98
#if defined(__GNUC__)
99
#pragma GCC diagnostic pop
100
#endif
// defined(__GNUC__)
101
126
[[nodiscard]]
bool
127
is_match
(std::string_view input, std::string_view pattern)
128
{
129
if
(std::empty (pattern))
130
{
131
return
std::empty (input);
132
}
133
134
if
(std::empty (input))
135
{
136
return
pattern[0] ==
'*'
?
is_match
(input, pattern.substr (1))
137
:
false
;
138
}
139
140
if
(pattern[0] !=
'?'
and pattern[0] !=
'*'
and pattern[0] != input[0])
141
{
142
return
false
;
143
}
144
145
if
(pattern[0] ==
'*'
)
146
{
147
for
(
decltype
(std::size (input)) i = 0u; i <= std::size (input);
148
++i)
149
{
150
if
(
is_match
(input.substr (i), pattern.substr (1)))
151
{
152
return
true
;
153
}
154
}
155
return
false
;
156
}
157
158
return
is_match
(input.substr (1), pattern.substr (1));
159
}
160
161
}
// namespace utility
162
// --------------------------------------------------------------------------
163
}
// namespace micro_os_plus::micro_test_plus
164
165
// ----------------------------------------------------------------------------
166
167
#endif
// defined(MICRO_OS_PLUS_MICRO_TEST_PLUS_ENABLED)
168
169
// ----------------------------------------------------------------------------
micro_os_plus::micro_test_plus::utility::extract_file_name
const char * extract_file_name(const char *path) noexcept
Extracts the file name component from a full path.
Definition
utility.cpp:87
micro_os_plus::micro_test_plus::utility::is_match
bool is_match(std::string_view input, std::string_view pattern)
Check if a string matches a pattern.
Definition
utility.cpp:127
micro_os_plus::micro_test_plus::utility
Utility functions for the µTest++ testing framework.
Definition
utility-inlines.h:65
micro_os_plus::micro_test_plus
Primary namespace for the µTest++ testing framework.
Definition
deferred-reporter.h:82
utility.h
C++ header file with declarations for the µTest++ utility helpers.
src
utility.cpp
Generated by
1.17.0