This repository has been archived on 2021-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
2019-12-17 15:05:27 +01:00
|
|
|
#include <cstring>
|
|
|
|
|
2019-11-14 22:12:20 +01:00
|
|
|
#ifndef STRING_HH
|
|
|
|
#define STRING_HH
|
|
|
|
class String {
|
|
|
|
public:
|
|
|
|
|
|
|
|
String(const char* str="") : _s(0) { insert(str) ; }
|
|
|
|
String(const String& a) : _s(0) { insert(a._s) ; }
|
|
|
|
~String() { delete[] _s ; }
|
|
|
|
|
2019-12-17 15:05:27 +01:00
|
|
|
String& operator=( const String& a );
|
|
|
|
String& operator+=( const String& a );
|
|
|
|
|
|
|
|
operator const char* const() { return data(); }
|
|
|
|
|
2019-11-14 22:12:20 +01:00
|
|
|
int length() const { return _len ; }
|
|
|
|
const char* data() const { return _s ; }
|
|
|
|
|
2019-12-17 15:05:27 +01:00
|
|
|
|
2019-11-14 22:12:20 +01:00
|
|
|
private:
|
|
|
|
|
|
|
|
char* _s ;
|
|
|
|
int _len ;
|
|
|
|
|
|
|
|
void insert(const char* str) { // private helper function
|
|
|
|
_len = strlen(str) ;
|
|
|
|
if (_s) delete[] _s ;
|
|
|
|
_s = new char[_len+1] ;
|
|
|
|
strcpy(_s,str) ;
|
|
|
|
}
|
|
|
|
|
|
|
|
} ;
|
|
|
|
|
|
|
|
#endif
|