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() [code]

Constructs an empty 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(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&& other) [code]

Move constructor.

HybridString(const HybridString& other) [code]

Copy constructor.

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 operator=(HybridString&& other) [code]

Move assignment operator.

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

Copy assignment operator.

operator StringView() const [code]

Conversion operator. Makes HybridString implicitly convertible to StringView.

StringView view() const [code]

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

Members Inherited From ply::StringMixin

  • template <typename T>
    T to(const T& defaultValue = subst::createDefault<T>()) const
  • explicit operator bool() const
  • bool isEmpty() const
  • StringView subStr(u32 start) const
  • StringView subStr(u32 start, u32 numBytes) const
  • StringView left(u32 numBytes) const
  • StringView shortenedBy(u32 numBytes) const
  • StringView right(u32 numBytes) const
  • friend s32 compare(const Derived& str0, const Derived& str1)
  • bool operator<(StringView other) const
  • bool operator==(StringView src) const
  • bool operator!=(StringView src) const
  • String operator+(StringView other) const
  • String operator*(u32 count) const
  • s32 findByte(char matchByte, u32 startPos = 0) const
  • template <typename MatchFuncOrChar>
    s32 findByte(const MatchFuncOrChar& matchFuncOrByte, u32 startPos = 0) const
  • template <typename MatchFuncOrChar>
    s32 rfindByte(const MatchFuncOrChar& matchFuncOrByte, u32 startPos) const
  • template <typename MatchFuncOrChar>
    s32 rfindByte(const MatchFuncOrChar& matchFuncOrByte) const
  • bool startsWith(StringView arg) const
  • bool endsWith(StringView arg) const
  • StringView trim(bool* matchFunc(char) = isWhite, bool left = true, bool right = true) const
  • StringView ltrim(bool* matchFunc(char) = isWhite) const
  • StringView rtrim(bool* matchFunc(char) = isWhite) const
  • String join(ArrayView<const StringView> comps) const
  • Array<StringView> splitByte(char sep) const
  • String upperAsc() const
  • String lowerAsc() const
  • String reversedBytes() const
  • String reversedUTF8() const
  • String filterBytes(char* filterFunc(char)) const
  • bool includesNullTerminator() const
  • HybridString withNullTerminator() const
  • StringView withoutNullTerminator() const
  • template <typename Hasher>
    void appendTo(Hasher& hasher) const