micro-test-plus
4.1.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 defined(MICRO_OS_PLUS_INCLUDE_CONFIG_H)
38
#include <micro-os-plus/config.h>
39
#endif
// MICRO_OS_PLUS_INCLUDE_CONFIG_H
40
41
#include "
micro-os-plus/micro-test-plus/utility.h
"
42
43
// ----------------------------------------------------------------------------
44
45
#if defined(__GNUC__)
46
#pragma GCC diagnostic ignored "-Waggregate-return"
47
#if defined(__clang__)
48
#pragma clang diagnostic ignored "-Wc++98-compat"
49
#endif
50
#endif
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
#if defined(__clang__)
63
#pragma clang diagnostic ignored "-Wdocumentation"
64
#endif
65
#endif
84
[[nodiscard]]
const
char
*
85
extract_file_name
(
const
char
* path)
noexcept
86
{
87
const
std::string_view sv{ path };
88
const
auto
pos = sv.find_last_of (
"/\\"
);
89
if
(pos == std::string_view::npos)
90
{
91
return
path;
// No separators found, return original string.
92
}
93
return
sv.substr (pos + 1).data ();
94
}
95
120
#if defined(__GNUC__)
121
#pragma GCC diagnostic pop
122
#endif
123
[[nodiscard]]
bool
124
is_match
(std::string_view input, std::string_view pattern)
125
{
126
if
(std::empty (pattern))
127
{
128
return
std::empty (input);
129
}
130
131
if
(std::empty (input))
132
{
133
return
pattern[0] ==
'*'
?
is_match
(input, pattern.substr (1))
134
:
false
;
135
}
136
137
if
(pattern[0] !=
'?'
and pattern[0] !=
'*'
and pattern[0] != input[0])
138
{
139
return
false
;
140
}
141
142
if
(pattern[0] ==
'*'
)
143
{
144
for
(
decltype
(std::size (input)) i = 0u; i <= std::size (input);
145
++i)
146
{
147
if
(
is_match
(input.substr (i), pattern.substr (1)))
148
{
149
return
true
;
150
}
151
}
152
return
false
;
153
}
154
155
return
is_match
(input.substr (1), pattern.substr (1));
156
}
157
158
}
// namespace utility
159
160
// ==========================================================================
161
}
// namespace micro_os_plus::micro_test_plus
162
163
// ----------------------------------------------------------------------------
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:85
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:124
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