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_EQUAL(full, "Hello World ! with values 42 3.500000");
};
#define TTS_EQUAL(LHS, RHS,...)
Performs equality comparison between two expressions.
Definition relation.hpp:134
#define TTS_CASE(ID)
Introduces a new test scenario and registers it into the current test driver.
Definition case.hpp:139
auto constexpr typename_
Evaluates to an object containing the name of the type T in readable form.
Definition typename.hpp:126
Lightweight string-like object.
Definition text.hpp:39
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)
 Move constructor.
 
 text (text const &other)
 Copy constructor.
 
 ~text ()
 Destructor.
 
decltype(autobegin ()
 Get an iterator to the beginning of the text.
 
decltype(autobegin () const
 Get a const iterator to the beginning of the text.
 
chardata ()
 Get a pointer to the underlying character data.
 
char constdata () const
 
decltype(autoend ()
 Get an iterator to the end of the text.
 
decltype(autoend () 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)
 Move assignment operator.
 
textoperator= (text const &other)
 Copy assignment operator.
 
int size () const
 Get the size of the text.
 
void swap (text &o)
 Swap contents with another text instance.
 

Friends

template<_::stream OS>
OSoperator<< (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
inline

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