micro-test-plus
5.0.0
µ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
#if __has_include(<micro-os-plus/project-config.h>)
38
#include <micro-os-plus/project-config.h>
39
#elif __has_include(<micro-os-plus/config.h>)
40
#pragma message \
41
"micro-os-plus/config.h is deprecated, rename to micro-os-plus/project-config.h and include it instead of micro-os-plus/config.h"
42
#include <micro-os-plus/config.h>
43
#endif
// __has_include(<micro-os-plus/project-config.h>)
44
45
#if __has_include(<micro-os-plus/micro-test-plus-defines.h>)
46
#include <micro-os-plus/micro-test-plus-defines.h>
47
#endif
// __has_include(<micro-os-plus/micro-test-plus-defines.h>)
48
49
#include "
micro-os-plus/micro-test-plus/utility.h
"
50
51
// ----------------------------------------------------------------------------
52
53
#if defined(__GNUC__)
54
#pragma GCC diagnostic ignored "-Waggregate-return"
55
#if defined(__clang__)
56
#pragma clang diagnostic ignored "-Wc++98-compat"
57
#endif
58
#endif
59
60
// ============================================================================
61
62
namespace
micro_os_plus::micro_test_plus
63
{
64
// --------------------------------------------------------------------------
65
66
namespace
utility
67
{
68
#if defined(__GNUC__)
69
#pragma GCC diagnostic push
70
#if defined(__clang__)
71
#pragma clang diagnostic ignored "-Wdocumentation"
72
#endif
73
#endif
92
[[nodiscard]]
const
char
*
93
extract_file_name
(
const
char
* path)
noexcept
94
{
95
const
std::string_view sv{ path };
96
const
auto
pos = sv.find_last_of (
"/\\"
);
97
if
(pos == std::string_view::npos)
98
{
99
return
path;
// No separators found, return original string.
100
}
101
return
sv.substr (pos + 1).data ();
102
}
103
128
#if defined(__GNUC__)
129
#pragma GCC diagnostic pop
130
#endif
131
[[nodiscard]]
bool
132
is_match
(std::string_view input, std::string_view pattern)
133
{
134
if
(std::empty (pattern))
135
{
136
return
std::empty (input);
137
}
138
139
if
(std::empty (input))
140
{
141
return
pattern[0] ==
'*'
?
is_match
(input, pattern.substr (1))
142
:
false
;
143
}
144
145
if
(pattern[0] !=
'?'
and pattern[0] !=
'*'
and pattern[0] != input[0])
146
{
147
return
false
;
148
}
149
150
if
(pattern[0] ==
'*'
)
151
{
152
for
(
decltype
(std::size (input)) i = 0u; i <= std::size (input);
153
++i)
154
{
155
if
(
is_match
(input.substr (i), pattern.substr (1)))
156
{
157
return
true
;
158
}
159
}
160
return
false
;
161
}
162
163
return
is_match
(input.substr (1), pattern.substr (1));
164
}
165
166
}
// namespace utility
167
168
// ==========================================================================
169
}
// namespace micro_os_plus::micro_test_plus
170
171
// ----------------------------------------------------------------------------
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:93
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:132
micro_os_plus::micro_test_plus::utility
Utility functions for the µTest++ testing framework.
Definition
utility-inlines.h:64
micro_os_plus::micro_test_plus
Primary namespace for the µTest++ testing framework.
utility.h
C++ header file with declarations for the µTest++ utility helpers.
src
utility.cpp
Generated by
1.17.0