60 lines
1.4 KiB
C++
60 lines
1.4 KiB
C++
#pragma once
|
|
|
|
#include <cstring>
|
|
|
|
namespace Gedeng {
|
|
|
|
class String {
|
|
public:
|
|
/// Create a new empty String
|
|
String();
|
|
|
|
/// Create a new String out of a char array.
|
|
/// The given character array must be \0-terminated.
|
|
explicit String(const char *stringText);
|
|
|
|
/// Copy constructor
|
|
String(const String &other);
|
|
|
|
/// Copy assignment operator
|
|
String &operator=(const String &other);
|
|
|
|
/// Move constructor
|
|
String(String &&other);
|
|
|
|
/// Move assignment operator
|
|
String &operator=(String &&other);
|
|
|
|
/// += operators for concatenate
|
|
/// Used in the + operator as well (defined outside the class)
|
|
String &operator+=(const String &other);
|
|
String &operator+=(const char *other);
|
|
|
|
/// Conversion to char pointer
|
|
operator const char *() const;
|
|
|
|
~String();
|
|
|
|
/// Append a String at the end of this String.
|
|
void concatenate(const String &other);
|
|
|
|
/// Append characters at the end of this String.
|
|
/// The given character array must be \0-terminated.
|
|
void concatenate(const char *other);
|
|
|
|
/// Return the internal char array representation of this String.
|
|
/// Note that calling concatenate() on the String invalidates this returned
|
|
/// pointer.
|
|
const char *c_str() const;
|
|
|
|
/// Return the length of the String (without the terminator).
|
|
size_t getLength() const;
|
|
|
|
private:
|
|
size_t length;
|
|
|
|
char *text;
|
|
};
|
|
|
|
} // namespace Gedeng
|