xrpld
Loading...
Searching...
No Matches
xrpl::NullTerminatedView Class Reference

A string that is known to reach its terminating null. More...

#include <StringUtilities.h>

Collaboration diagram for xrpl::NullTerminatedView:

Public Member Functions

consteval NullTerminatedView (std::string_view view)
 Build a view from one that reaches its terminating null.
constexpr operator std::string_view () const noexcept
constexpr std::string_view view () const noexcept
constexpr char const * asCString () const noexcept

Private Attributes

char const * data_
std::size_t size_

Detailed Description

A string that is known to reach its terminating null.

Converts to std::string_view, so it compares and hashes as one. Unlike a view, asCString() may be handed to a reader that expects a C string, such as json::StaticString.

The only constructor is consteval and rejects a view that stops before the null, so the property holds by construction and no caller asserts it.

Definition at line 202 of file StringUtilities.h.

Constructor & Destructor Documentation

◆ NullTerminatedView()

xrpl::NullTerminatedView::NullTerminatedView ( std::string_view view)
explicitconsteval

Build a view from one that reaches its terminating null.

Explicit, so that a plain view cannot become a proof of termination by accident. The conversion the other way stays implicit.

Parameters
viewThe string to hold. Rejected at compile time if it stops before its terminating null, or has no data.

Definition at line 214 of file StringUtilities.h.

Member Function Documentation

◆ operator std::string_view()

xrpl::NullTerminatedView::operator std::string_view ( ) const
constexprnoexcept

Definition at line 222 of file StringUtilities.h.

◆ view()

std::string_view xrpl::NullTerminatedView::view ( ) const
nodiscardconstexprnoexcept
Returns
The string as a view.

Definition at line 231 of file StringUtilities.h.

◆ asCString()

char const * xrpl::NullTerminatedView::asCString ( ) const
nodiscardconstexprnoexcept
Returns
The string as a C string. Never null.

Definition at line 240 of file StringUtilities.h.

Member Data Documentation

◆ data_

char const* xrpl::NullTerminatedView::data_
private

Definition at line 246 of file StringUtilities.h.

◆ size_

std::size_t xrpl::NullTerminatedView::size_
private

Definition at line 247 of file StringUtilities.h.