TTS v3.0.0
The Tiny Test System
Loading...
Searching...
No Matches
tts::text Struct Reference

Lightweight string-like object. More...

Detailed Description

Lightweight string-like object.

tts::text is a simple string-like object that can be used to represent and manipulate text data in TTS. It provides basic functionalities such as construction from formatted strings, concatenation, and stream output support

Example

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
TTS_CASE("Using tts::text")
{
tts::text hello("Hello ");
tts::text world("World !");
tts::text qty(" with values %d %f", 42, 3.5f);
tts::text full = hello + world + qty;
TTS_EQUAL(full, "Hello World ! with values 42 3.500000");
};
See also
tts::as_text

Public Member Functions

 text ()
 Default constructor.
template<std::size_t N>
 text (char const (&data)[N])
 Construct from fixed-size C-style string.
template<typename... Args>
 text (char const *format, Args... args)
 Construct from formatted string.
 text (char const *ptr)
 Construct from C-style string.
 text (text &&other) noexcept
 Move constructor.
 text (text const &other)
 Copy constructor.
 ~text ()
 Destructor.
decltype(auto) begin ()
 Get an iterator to the beginning of the text.
decltype(auto) begin () const
 Get a const iterator to the beginning of the text.
char const * data () const
decltype(auto) end ()
 Get an iterator to the end of the text.
decltype(auto) end () const
 Get a const iterator to the end of the text.
bool is_empty () const
 Check if the text is empty.
text operator+ (text const &other) const
 Concatenate and return a new text instance.
textoperator+= (char const *other)
 Concatenate a C-style string.
textoperator+= (text const &other)
 Concatenate another text instance.
textoperator= (text &&other) noexcept
 Move assignment operator.
textoperator= (text const &other)
 Copy assignment operator.
size_t size () const
 Get the size of the text.
void swap (text &o) noexcept
 Swap contents with another text instance.

Friends

template<_::stream OS>
OS & operator<< (OS &os, text const &t)
 Stream output operator.
template<std::size_t N>
auto operator<=> (text const &a, char const (&b)[N]) noexcept
 Three-way comparison operator with C-style string.
std::strong_ordering operator<=> (text const &a, text const &b) noexcept
 Three-way comparison operator with other text instance.
template<std::size_t N>
bool operator== (text const &a, char const (&b)[N]) noexcept
 Equality comparison operator with C-style string.
bool operator== (text const &a, text const &b) noexcept
 Equality comparison operator.

Constructor & Destructor Documentation

◆ text()

template<typename... Args>
tts::text::text ( char const * format,
Args... args )
inlineexplicit

Construct from formatted string.

tts::text is constructible from a C-style format string and a variable number of arguments.

Parameters
formatC-style format string
argsArguments to format according to format

Member Function Documentation

◆ data()

char const * tts::text::data ( ) const
inlinenodiscard

Get a pointer to the constant underlying character data Returns an empty string literal if data_ is null to prevent s crashes