micro-test-plus 3.2.0
µTest++, a lightweight testing framework for embedded platforms
Loading...
Searching...
No Matches
Utility functions

Functions to assist in string operations. More...

Functions

bool micro_os_plus::micro_test_plus::utility::is_match (std::string_view input, std::string_view pattern)
 Check if a string matches a pattern.
 
template<class T = std::string_view, class Delim_T >
auto micro_os_plus::micro_test_plus::utility::split (T input, Delim_T delim) -> std::vector< T >
 Split a string into a vector of sub-strings.
 

Detailed Description

Functions to assist in string operations.

Function Documentation

◆ is_match()

bool micro_os_plus::micro_test_plus::utility::is_match ( std::string_view input,
std::string_view pattern )

Check if a string matches a pattern.

Parameters
[in]inputString view to check.
[in]patternSting view with the pattern.
Returns
True if the string matches the pattern.

For tests comparing strings, in addition to exact matches, it is also possible to check matches with patterns like * (for any characters) and ? (for a single character)

Examples
mt::expect (mt::utility::is_match ("abc", "a?c")) << "abc matches a?c";
mt::expect (mt::utility::is_match ("abc", "a*c")) << "abc matches a*c";

Definition at line 123 of file micro-test-plus.cpp.

◆ split()

template<class T = std::string_view, class Delim_T >
auto micro_os_plus::micro_test_plus::utility::split ( T input,
Delim_T delim ) -> std::vector< T >

Split a string into a vector of sub-strings.

For tests handling strings, this function template allows to split a string into a vector of substrings, using a delimiter.

Example
mt::expect (std::vector<std::string_view>{ "a", "b" }
== mt::utility::split<std::string_view> ("a.b", "."))
<< "a.b splits into [a,b]";
Template Parameters
TType of the input string.
Delim_TType of the delimiter.
Parameters
[in]inputInput string to split.
[in]delimDelimiter string.
Returns
An array of strings.

Definition at line 169 of file inlines.h.