StaticString.hpp

String substitute with a fixed max character count and always in place.

A fixed number of chars are reserved for the string; errors will trigger for longer attempts. The last allocated byte stores the number of unused positions in the string; this naturally becomes zero (the final character in a string) when all positions are used.

Note

Status: ALPHA

Typedefs

using ShortString = StaticString<31>
template<size_t NUM_CHARS, typename CHAR_T = char>
class StaticString
#include <StaticString.hpp>

Public Functions

inline StaticString()
StaticString(const StaticString&) = default
inline StaticString(const std::string &in)
inline StaticString(CHAR_T const *in)
template<size_t SIZE>
inline StaticString(CHAR_T in[SIZE])
StaticString &operator=(const StaticString&) = default
inline StaticString &operator=(const std::string &in)
inline StaticString &operator=(CHAR_T const *in)
template<size_t SIZE>
inline StaticString &operator=(CHAR_T in[SIZE])
inline CHAR_T *data()
inline const CHAR_T *data() const
inline size_t size() const
inline void resize(size_t new_size)
inline void resize(size_t new_size, CHAR_T filler)
inline CHAR_T &operator[](size_t id)
inline CHAR_T operator[](size_t id) const
template<typename T>
inline bool operator==(const T &in) const
template<typename T>
inline bool operator!=(const T &in) const
template<typename T>
inline bool operator<(const T &in) const
template<typename T>
inline bool operator<=(const T &in) const
template<typename T>
inline bool operator>(const T &in) const
template<typename T>
inline bool operator>=(const T &in) const
inline bool operator==(CHAR_T const *in) const
inline bool operator!=(CHAR_T const *in) const
inline bool operator<(CHAR_T const *in) const
inline bool operator<=(CHAR_T const *in) const
inline bool operator>(CHAR_T const *in) const
inline bool operator>=(CHAR_T const *in) const
inline operator CHAR_T*()
inline operator const CHAR_T*() const
inline operator std::string() const
inline std::string AsString() const
inline StaticString &push_back(CHAR_T c)
inline StaticString &append(const CHAR_T *in_str, size_t len)
inline StaticString &append(const std::string &in_str)
template<size_t SIZE>
inline StaticString &append(CHAR_T in_str[SIZE])
template<size_t NUM_CHARS2>
inline StaticString &append(StaticString<NUM_CHARS2, CHAR_T> in_str)

Private Types

using ss_size_t = std::conditional_t<(NUM_CHARS <= 256), uint8_t, uint16_t>

Private Functions

inline StaticString &CopyFrom(const CHAR_T *in, size_t len)
inline int Compare(const CHAR_T *in, size_t len) const

Private Members

array<CHAR_T, NUM_CHARS> string
ss_size_t str_size = 0

Private Static Attributes

static constexpr const size_t MAX_CHARS = NUM_CHARS - 1