micro-test-plus 4.1.0
µTest++ Testing Framework
Loading...
Searching...
No Matches
utility-inlines.h
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
40
41#ifndef MICRO_TEST_PLUS_UTILITY_INLINES_H_
42#define MICRO_TEST_PLUS_UTILITY_INLINES_H_
43
44// ----------------------------------------------------------------------------
45
46#ifdef __cplusplus
47
48// ----------------------------------------------------------------------------
49
50#if defined(__GNUC__)
51#pragma GCC diagnostic push
52#pragma GCC diagnostic ignored "-Waggregate-return"
53#if defined(__clang__)
54#pragma clang diagnostic ignored "-Wc++98-compat"
55#endif
56#endif
57
58// ============================================================================
59
61{
62 // --------------------------------------------------------------------------
63 namespace utility
64 {
86 template <class T = std::string_view, class Delim_T>
87 [[nodiscard]] auto
88 split (T input, Delim_T delim) -> std::vector<T>
89 {
90 std::vector<T> output{};
91 std::size_t first{};
92 while (first < std::size (input))
93 {
94 const auto second = input.find_first_of (delim, first);
95 if (first != second)
96 {
97 output.emplace_back (input.substr (first, second - first));
98 }
99 if (second == T::npos)
100 {
101 break;
102 }
103 first = second + 1;
104 }
105 return output;
106 }
107
108 // ------------------------------------------------------------------------
109 } // namespace utility
110
111 // --------------------------------------------------------------------------
112} // namespace micro_os_plus::micro_test_plus
113
114#if defined(__GNUC__)
115#pragma GCC diagnostic pop
116#endif
117
118// ----------------------------------------------------------------------------
119
120#endif // __cplusplus
121
122// ----------------------------------------------------------------------------
123
124#endif // MICRO_TEST_PLUS_UTILITY_INLINES_H_
125
126// ----------------------------------------------------------------------------
auto split(T input, Delim_T delim) -> std::vector< T >
Split a string into a vector of sub-strings.
Utility functions for the µTest++ testing framework.
Primary namespace for the µTest++ testing framework.