#ifndef STRING_H_ #define STRING_H_ namespace Strings { class Content { protected: int nContent; public: int length() const { return nContent; } Content() : nContent(0) { } }; class Range { public: int iRange; int nRange; public: Range(const Content& o,int i,int n); }; class Base: public Content { public: int nBuffer; protected: enum { POT = 8, QUANTA = (1 << POT) }; static int sizeFor(int n) { return QUANTA + ((n - 1) & ~(QUANTA - 1)); } public: Base() : nBuffer(0) { } }; } namespace UCS { using namespace Strings; class String: public Base { protected: int* pBuffer; String(const String&); protected: void resize(int); public: String(); String(int); ~String() { delete pBuffer; } public: void upsize(int n) { if (nBuffer < n) { resize(n); } } public: void copy(String&,Range); void copy(String& s) { copy(s, 0, s.nContent); } void copy(String& s,int i,int n) { copy(s, Range(s, i, n)); } void append(String&,Range); void append(String& s) { append(s, Range(s, 0, s.nContent)); } void append(String& s,int i,int n) { append(s, Range(s, i, n)); } int findChar(int) const; public: int* asChars() const { return pBuffer; } void from(const int*,int); public: int room() const { return nBuffer - nContent; } void setLength(int n) { nContent = n; } void add(int c) { pBuffer[nContent++] = c; } public: int compare(const String&) const; }; } namespace UTF8 { using namespace Strings; class String: public Base { protected: char* pBuffer; String(const String&); protected: void resize(int n); public: void upsize(int n) { if (nBuffer < n) { resize(n); } } public: String() : pBuffer(0) { nBuffer = QUANTA; pBuffer= new char[nBuffer]; } String(int n) : pBuffer(0) { nBuffer = sizeFor(n); pBuffer= new char[nBuffer]; } ~String() { delete pBuffer; } public: void copy(String&,Range); void copy(String& s) { copy(s, 0, s.nContent); } void copy(String& s,int i,int n) { copy(s, Range(s, i, n)); } void append(String&,Range); void append(String& s) { append(s, Range(s, 0, s.nContent)); } void append(String& s,int i,int n) { append(s, Range(s, i, n)); } int findChar(int) const; public: char* asChars(); void from(const char*); void recode(); public: void convertFrom(const UCS::String&); void convertTo(UCS::String&) const; public: int compare(const String&) const; }; } #endif