#ifndef STRING_H #define STRING_H #include namespace ecci { class String { public: /// Indicates a non valid length or index static const size_t npos = (size_t)-1; private: /// Length of this string size_t length; /// Pointer to the characters of this string in heap char* text; #ifdef TESTING static size_t instanceCount; #endif public: /// Default constructor (ctor) /// Conversion constructor String(const char* text = "", size_t len = npos); /// Conversion constructor String(char ch); /// Copy constructor String(const String& other); /// Move constructor String(String&& other); /// Destructor (dtor) ~String(); /// Copy assignment operator String& operator=(const String& other); /// Move assignment operator String& operator=(String&& other); #ifdef TESTING inline static size_t getInstanceCount() { return instanceCount; } #endif public: /// Get the length of this string inline size_t getLength() const { return this->length; } /// Get read-only access to the internal null-terminated string inline const char* c_str() const { return this->text; } /// Get read-only access to the internal null-terminated string // inline operator const char*() const { return this->text; } /// Get read & write access to the char at position @a index inline char& operator[](size_t index) { return text[index]; } /// Get read-only access to the char at position @a index inline const char& operator[](size_t index) const { return text[index]; } /// Allows cout << str1 << ... friend inline std::ostream& operator<<(std::ostream& out, const String& str) { return out << str.text; } /// Concatenates this string with other string const String operator+(const String& other) const; private: /// Capacity constructor explicit String(size_t capacity); }; } // namespace ecci #endif // STRING_H