xentara-utils v2.0.4
The Xentara Utility Library
Loading...
Searching...
No Matches
xentara::utils::json::encoder::String Class Referencefinal

A class used for writing a JSON string value progressively. More...

#include <xentara/utils/json/encoder/String.hpp>

+ Inheritance diagram for xentara::utils::json::encoder::String:

Public Member Functions

 String ()=delete
 This type is not user-constructible.
 
 ~String () noexcept(false)
 Destructor.
 
template<std::convertible_to< std::string_view > String>
auto append (const String &text) -> void
 Appends text to the string.
 
auto close () -> void
 Writes the termination of the object, if it has not already been written.
 

Detailed Description

A class used for writing a JSON string value progressively.

This class can be used to compose JSON string on the fly by concatenating string fragments.

Objects of this class can be moved, but not copied.

Constructor & Destructor Documentation

◆ String()

xentara::utils::json::encoder::String::String ( )
delete

This type is not user-constructible.

◆ ~String()

xentara::utils::json::encoder::String::~String ( )

Destructor.

This destructor writes the closing quotes, if they have not already been written.

This destructor will throw an exception if the closing quotes cannot be written. To prevent termination of the program, no exceptions are thrown during stack windup, though. You can prevent the destructor from throwing any exceptions by closing the string manually beforehand using close().

Exceptions
std::runtime_errorAn error occured writing to the stream

Member Function Documentation

◆ append()

auto xentara::utils::json::encoder::String::append ( const String text) -> void

Appends text to the string.

Parameters
textThe text to append
Exceptions
std::runtime_errorAn error occured writing to the stream

◆ close()

auto xentara::utils::json::encoder::String::close ( ) -> void

Writes the termination of the object, if it has not already been written.

Note
This function can be safely called on objects that have been moved away using the move constructor or move assignment operator.
Exceptions
std::runtime_errorAn error occured writing to the stream