Skip to main content

basic_c_string Struct Template

A C string operand of a comparator. More...

Declaration​

template <character Char_T>
struct micro_os_plus::micro_test_plus::detail::basic_c_string<Char_T> { ... }

Included Headers​

Public Constructors Index​

template <character Char_T>
constexprbasic_c_string (const Char_T *str) noexcept

Constructs the operand from a pointer to a null-terminated string. More...

template <character Char_T>
constexprbasic_c_string (const Char_T *str, std::size_t capacity) noexcept

Constructs the operand from an array of characters. More...

Public Member Functions Index​

template <character Char_T>
constexpr boolis_null (void) const noexcept

Returns whether the operand is a null pointer. More...

template <character Char_T>
constexpr auto view (void) const noexcept -> std::basic_string_view< Char_T >

Returns the characters, as a string view. More...

Private Member Attributes Index​

template <character Char_T>
std::size_tsize_

The number of characters, without the terminator. More...

template <character Char_T>
const Char_T *str_

The first character, or nullptr. More...

Description​

A C string operand of a comparator.

The comparators convert the arrays (including the string literals) and the pointers of the character types to this type (see as_operand()), so that they are compared by content, as a reader of a test expects, and not by address. A null pointer is equal only to another null pointer (not to an empty string), and is less than any string.

The characters are not copied; the operand must outlive the comparison, which is always the case within a check.

Template Parameters
Char_T

The character type; it satisfies character.

Definition at line 1673 of file detail.h.

Public Constructors​

basic_c_string()​

template <character Char_T>
micro_os_plus::micro_test_plus::detail::basic_c_string< Char_T >::basic_c_string (const Char_T * str)
explicit constexpr noexcept

Constructs the operand from a pointer to a null-terminated string.

Parameters
str

The string, or nullptr.

The length is computed with std::char_traits<Char_T>::length(), which, unlike strlen(), can be evaluated at compile time.

Declaration at line 1681 of file detail.h, definition at line 1498 of file detail-inlines.h.

1498 template <character Char_T>
1500 const Char_T* str) noexcept
1501 : str_{ str },
1502 size_{ str == nullptr ? 0 : std::char_traits<Char_T>::length (str) }
1503 {

Reference micro_os_plus::micro_test_plus::detail::basic_c_string< Char_T >::str_.

basic_c_string()​

template <character Char_T>
micro_os_plus::micro_test_plus::detail::basic_c_string< Char_T >::basic_c_string (const Char_T * str, std::size_t capacity)
constexpr noexcept

Constructs the operand from an array of characters.

The string ends at the first null character, or at the end of the array, so that an array without a terminator is not read beyond its end.

Parameters
str

The first character of the array.

capacity

The number of elements of the array.

The characters are counted up to the first null character, or up to capacity.

Declaration at line 1694 of file detail.h, definition at line 1511 of file detail-inlines.h.

1511 template <character Char_T>
1513 const Char_T* str, std::size_t capacity) noexcept
1514 : str_{ str }, size_{ capacity }
1515 {
1516 // Search within the array only; the view avoids indexing the raw
1517 // pointer.
1518 const std::size_t terminator
1519 = std::basic_string_view<Char_T>{ str, capacity }.find (Char_T{});
1520 if (terminator != std::basic_string_view<Char_T>::npos)
1521 {
1522 size_ = terminator;
1523 }

Reference micro_os_plus::micro_test_plus::detail::basic_c_string< Char_T >::str_.

Public Member Functions​

is_null()​

template <character Char_T>
bool micro_os_plus::micro_test_plus::detail::basic_c_string< Char_T >::is_null (void)
nodiscard constexpr noexcept

Returns whether the operand is a null pointer.

Parameters

None.

Return Values
true

The operand is a null pointer.

false

The operand is a string, possibly empty.

Returns whether the stored pointer is null.

Declaration at line 1717 of file detail.h, definition at line 1543 of file detail-inlines.h.

1543 constexpr bool
1544 basic_c_string<Char_T>::is_null (void) const noexcept
1545 {
1546 return str_ == nullptr;

Reference micro_os_plus::micro_test_plus::detail::basic_c_string< Char_T >::str_.

Referenced by micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<.

view()​

template <character Char_T>
std::basic_string_view< Char_T > micro_os_plus::micro_test_plus::detail::basic_c_string< Char_T >::view (void)
nodiscard constexpr noexcept

Returns the characters, as a string view.

Parameters

None.

Returns

The characters, without the terminator; empty for a null pointer.

Returns an empty view for a null pointer.

Declaration at line 1706 of file detail.h, definition at line 1531 of file detail-inlines.h.

1531 constexpr std::basic_string_view<Char_T>
1532 basic_c_string<Char_T>::view (void) const noexcept
1533 {
1534 return str_ == nullptr ? std::basic_string_view<Char_T>{}
1535 : std::basic_string_view<Char_T>{ str_, size_ };

References micro_os_plus::micro_test_plus::detail::basic_c_string< Char_T >::size_ and micro_os_plus::micro_test_plus::detail::basic_c_string< Char_T >::str_.

Referenced by micro_os_plus::micro_test_plus::detail::expression_formatter::operator<<.

Private Member Attributes​

size_​

template <character Char_T>
std::size_t micro_os_plus::micro_test_plus::detail::basic_c_string< Char_T >::size_

The number of characters, without the terminator.

Computed by the constructors; zero for a null pointer.

Definition at line 1734 of file detail.h.

1734 std::size_t size_;

Referenced by micro_os_plus::micro_test_plus::detail::basic_c_string< Char_T >::view.

str_​

template <character Char_T>
const Char_T* micro_os_plus::micro_test_plus::detail::basic_c_string< Char_T >::str_

The documentation for this struct was generated from the following files:


Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.