Здравствуйте, roma_k, Вы писали:
_>Оцените пожалуйста, интересны все мои ошибки, особенно в реализации операторов !!!
_>// Заголовок
class nvString
{
public:
// constructor
nvString();
// Construct a string from a char pointer
nvString(const char* inStr);
// Copy-constructor
nvString(const nvString& inStr);
// destructor
virtual ~nvString();
// Type cast to char pointer
inline operator const char *() const
{ return m_buffer; }
// Indexing operator
inline char operator[](int i) const
{ return m_buffer[i]; }
// Сделай еще что-нибудь типа "GetAt()" с проверкой индекса
// Char pointer atribuition operator
const nvString& operator=(const char* inStr);
// Atribuition operator
const nvString& operator=(const nvString& inStr);
// Такие два оператора, имхо, лучше делать глобальными
// Concatenation operator with a char pointer
nvString operator+(const char* inStr);
// Concatenation operator
nvString operator+(const nvString& inStr);
// Self-concatenation operator with a char pointer
const nvString& operator+=(const char* inStr);
// Self-concatenation operator
const nvString& operator+=(const nvString& inStr);
void Clear(void);
// Find a sub-string in the string
inline int Find(const char *str) const
{
char *pos=strstr(m_buffer,str);
if (pos == 0)
return -1;
return (int)(pos-m_buffer);
}
// Find the first occurrence of a character in the string
inline int Find(char c) const
{
char *pos = strchr(m_buffer,c);
if (pos == 0)
return -1;
return (int)(pos-m_buffer);
}
// Find the last occurrence of a character in the string
inline int FindLast(char c) const
{
char *pos = strrchr(m_buffer,c);
if (pos == 0)
return -1;
return (int)(pos-m_buffer);
}
// Change the 'i'-th character of the string
// Удобнее было бы еще и через индексирование сделать. Через прокси-класс :)
inline void SetChar(int i,char c)
{
if (i < (int)strlen(m_buffer))
m_buffer[i] = c;
}
// Crop the first 'n' characters of the string
inline void CropBegin(int n)
{
if (n < (int)strlen(m_buffer))
{
strcpy(m_buffer,&m_buffer[n]);
}
}
// А сравнения с nvString?
// equal compare operator
inline int operator==(const char *str) const
{ return strcmp(m_buffer,str)==0; }
inline int operator!=(const char *str) const
{ return strcmp(m_buffer,str)!=0; }
inline int operator>(const char *str) const
{ return strcmp(m_buffer,str)>0; }
inline int operator<(const char *str) const
{ return strcmp(m_buffer,str)<0; }
inline int operator>=(const char *str) const
{ return strcmp(m_buffer,str)>=0; }
inline int operator<=(const char *str) const
{ return strcmp(m_buffer,str)<=0; }
// Compare with a char pointer
inline int Compare(const char *str) const
{ return strcmp(m_buffer,str); }
// Compare the first 'n' characters of the string with a char pointer
inline int Compare(const char *str,int n) const
{ return strncmp(m_buffer,str,n); }
// Compare with a char pointer, case-insensitive flavour
inline int CompareNoCase(const char *str) const
{ return stricmp(m_buffer,str); }
// Change all characters to lower-case
inline void ToLower()
{ strlwr(m_buffer); }
// Change all characters to upper-case
inline void ToUpper()
{ strupr(m_buffer); }
// Return the length of the string in bytes
// Это кэшировать надо
inline int Length() const
{ return m_nLength; }
private:
char *m_buffer;
int m_nLength;
};