Skip to content

Class jac::OwnedString

ClassList > jac > OwnedString

An owning RAII handle for a QuickJS-allocated C string. More...

  • #include <ownedString.h>

Public Functions

Type Name
OwnedString () = default
OwnedString (ContextRef ctx, const char * str)
Wrap a QuickJS allocated, null-terminated string.
OwnedString (ContextRef ctx, const char * str, std::size_t len)
Wrap a QuickJS allocated string of a known length. The string may contain embedded null bytes.
const char * c_str () noexcept const
Get the underlying null-terminated C string.
const char * data () noexcept const
bool empty () noexcept const
string () const
string_view () noexcept const
std::size_t size () noexcept const
std::string_view view () noexcept const
Get a non-owning view of the string.

Detailed Description

The string must be allocated using QuickJS functions (JS_ToCString, JS_AtomToCString, etc.); it is released with JS_FreeCString when the handle is destroyed. The handle is move-only. Use view to obtain a (non-owning) std::string_view for inspection.

Public Functions Documentation

function OwnedString [1/3]

jac::OwnedString::OwnedString () = default

function OwnedString [2/3]

Wrap a QuickJS allocated, null-terminated string.

inline jac::OwnedString::OwnedString (
    ContextRef ctx,
    const char * str
) 

Parameters:

  • ctx context to work in
  • str string to take ownership of

function OwnedString [3/3]

Wrap a QuickJS allocated string of a known length. The string may contain embedded null bytes.

inline jac::OwnedString::OwnedString (
    ContextRef ctx,
    const char * str,
    std::size_t len
) 

Parameters:

  • ctx context to work in
  • str string to take ownership of
  • len length of the string in bytes

function c_str

Get the underlying null-terminated C string.

inline const char * jac::OwnedString::c_str () noexcept const

Returns:

const char*


function data

inline const char * jac::OwnedString::data () noexcept const

function empty

inline bool jac::OwnedString::empty () noexcept const

function string

inline jac::OwnedString::string () const

function string_view

inline jac::OwnedString::string_view () noexcept const

function size

inline std::size_t jac::OwnedString::size () noexcept const

function view

Get a non-owning view of the string.

inline std::string_view jac::OwnedString::view () noexcept const

Returns:

std::string_view valid for the lifetime of this handle


Friends Documentation

friend operator<<

inline std::ostream & jac::OwnedString::operator<< (
    std::ostream & os,
    const OwnedString & str
) 


The documentation for this class was generated from the following file src/jac/machine/ownedString.h