Get Involved

HybridString

A HybridString is a cross between a String and a StringView. It references a range of memory that is generally intended (but not required) to contain UTF-8-encoded text. The HybridString may or may not own the memory it points to, as determined by the isOwner flag. If isOwner is non-zero, the memory block owned by the HybridString will be freed from heap when the HybridString is destroyed. If isOwner is zero, the HybridString does not own the memory it points to, and the caller must ensure that the memory remains valid for the lifetime of the HybridString.

Header File

#include <ply-runtime/container/String.h>

Also included from <ply-runtime/Base.h>.

Data Members

 char* bytes [code]

The bytes. Should be treated as const if isOwner == 0.

 u32 isOwner : 1 [code]
 u32 numBytes : 31 [code]

Number of bytes and owner flag.

Member Functions

  HybridString::HybridString() [code]

Constructs an empty HybridString.

  HybridString::HybridString(StringView view) [code]

Constructs a HybridString that views the same memory block as view. view is expected to remain valid for the lifetime of the HybridString. No new memory is allocated.

  HybridString::HybridString(String&& str) [code]

Constructs a HybridString that takes ownership of the memory block owned by str. str is reset to an empty string.

  HybridString::HybridString(HybridString&& other) [code]

Move constructor.

  HybridString::HybridString(const HybridString& other) [code]

Copy constructor.

  HybridString::HybridString(const char* s) [code]

Construct a HybridString from a string literal. Compilers seem able to calculate its length at compile time (if optimization is enabled).

void HybridString::operator=(HybridString&& other) [code]

Move assignment operator.

void HybridString::operator=(const HybridString& other) [code]

Copy assignment operator.

HybridString::operator StringView() const [code]

Conversion operator. Makes HybridString implicitly convertible to StringView.

 StringView HybridString::view() const [code]

Explicitly creates a StringView into the HybridString. No new memory is allocated by this function.

Members Inherited From ply::StringMixin