Exemplo n.º 1
0
void SimpleString::replace(const char* to, const char* with)
{
    int c = count(to);
    int len = size();
    int tolen = PlatformSpecificStrLen(to);
    int withlen = PlatformSpecificStrLen(with);

    int newsize = len + (withlen * c) - (tolen * c) + 1;

    if (newsize) {
        char* newbuf = allocString(newsize);
        for (int i = 0, j = 0; i < len;) {
            if (PlatformSpecificStrNCmp(&buffer[i], to, tolen) == 0) {
                PlatformSpecificStrNCpy(&newbuf[j], with, withlen);
                j += withlen;
                i += tolen;
            }
            else {
                newbuf[j] = buffer[i];
                j++;
                i++;
            }
        }
        deallocString(buffer);
        buffer = newbuf;
        buffer[newsize-1] = '\0';
    }
    else {
        buffer = getEmptryString();
        buffer [0] = '\0';
    }
}
Exemplo n.º 2
0
void deallocMutableString() {
//	free((void *)MutableString), MutableString = NULL;
//	free((void *)MutableStringClass), MutableStringClass = NULL;
	release((void *)MutableString), MutableString = NULL;
	release((void *)MutableStringClass), MutableStringClass = NULL;
	deallocString();
}
Exemplo n.º 3
0
SimpleString& SimpleString::operator+=(const char* rhs)
{
    int len = this->size() + PlatformSpecificStrLen(rhs) + 1;
    char* tbuffer = allocString(len);
    PlatformSpecificStrCpy(tbuffer, this->buffer);
    PlatformSpecificStrCat(tbuffer, rhs);
    deallocString(buffer);
    buffer = tbuffer;
    return *this;
}
Exemplo n.º 4
0
SimpleString& SimpleString::operator=(const SimpleString& other)
{
	if (this != &other) {
		deallocString(buffer);
		int len = other.size() + 1;
		buffer = allocString(len);
		PlatformSpecificStrCpy(buffer, other.buffer);
	}
	return *this;
}
Exemplo n.º 5
0
 void String::setString(String & aString)
 {
     int newSize = stringLength(aString);
     deallocString(m_Characters);
     m_Characters = allocString(newSize + 1);
     m_Length = newSize;
     for(int i = 0; i < m_Length; i++)
     {
         m_Characters[i] = aString[i];
     }
     m_Characters[m_Length] = '\0';
 }
Exemplo n.º 6
0
 void String::setString(const char * aString)
 {
     int newSize = stringLength(aString);
     deallocString(m_Characters);
     m_Characters = allocString(newSize + 1); //+ 1 for null terminator
     m_Length = newSize;
     for(int i = 0; i < m_Length; i++)
     {
         m_Characters[i] = aString[i];
     }
     m_Characters[m_Length] = '\0';
 }
Exemplo n.º 7
0
 void String::appendChar(char aChar)
 {
     int bufferSize = 1 + m_Length;
     char * newString = allocString(bufferSize + 1);
     for(int i = 0; i < m_Length; i++)
     {
         newString[i] = m_Characters[i];
     }
     newString[m_Length] = aChar;
     deallocString(m_Characters);
     m_Characters = newString;
     m_Length = bufferSize;
     m_Characters[m_Length] = '\0';
 }
Exemplo n.º 8
0
 void String::appendString(String & aString)
 {
     int stringSize = stringLength(aString);
     int bufferSize = stringSize + m_Length;
     char * newString = allocString(bufferSize + 1);
     for(int i = 0; i < m_Length; i++)
     {
         newString[i] = m_Characters[i];
     }
     for(int i = 0; i < stringSize; i++)
     {
         newString[i + m_Length] = aString[i];
     }
     deallocString(m_Characters);
     m_Characters = newString;
     m_Length = bufferSize;
     m_Characters[m_Length] = '\0';
 }
Exemplo n.º 9
0
void SimpleString::split(const SimpleString& split, SimpleStringCollection& col) const
{
    int num = count(split);
    int extraEndToken = (endsWith(split)) ? 0 : 1;
    col.allocate(num + extraEndToken);

    char* str = buffer;
    char* prev;
    for (int i = 0; i < num; ++i) {
        prev = str;
        str = PlatformSpecificStrStr(str, split.buffer) + 1;
        int len = str - prev;
        char* sub = allocString(len+1);
        PlatformSpecificStrNCpy(sub, prev, len);
        sub[len] = '\0';
        col[i] = sub;
        deallocString(sub);
    }
    if (extraEndToken) {
        col[num] = str;
    }
}
Exemplo n.º 10
0
SimpleString::~SimpleString ()
{
    deallocString(buffer);
}
Exemplo n.º 11
0
 void String::allocBuffer(int aSize)
 {
     deallocString(m_Characters);
     m_Characters = allocString(aSize);
 }
Exemplo n.º 12
0
 String::~String()
 {
     deallocString(m_Characters);
     m_Length = 0;
 }