Class StringView

Class Documentation

class StringView
[source]

Non-owning, read-only view of a NUL-terminated string.

The referenced data must outlive the view. Construction from a const char* or a String is implicit so that existing call sites require no changes when a function parameter is widened from const String& to StringView.

Public Functions

StringView(const char *str)

Construct from a NUL-terminated C string.

StringView(const char *str, size_t len)

Construct from a pointer and an explicit length.

StringView(const String &str)

Construct from a String (caller must ensure lifetime).

inline const char *data() const

Pointer to the character data.

inline const char *c_str() const

NUL-terminated pointer to the character data.

inline size_t size() const

Number of characters (not counting the NUL terminator).

inline bool empty() const

True if the view has zero characters.

inline const char &operator[](size_t pos) const

Access the character at pos (unchecked).