Browse Source

Finished some more replace() functions for String_Type.

release/0.19
JustinAJ 10 years ago
parent
commit
510ac72c56
  1. 8
      Jupiter/String_Type.h
  2. 111
      Jupiter/String_Type_Imp.h
  3. BIN
      Release/Jupiter.lib

8
Jupiter/String_Type.h

@ -136,10 +136,10 @@ namespace Jupiter
//virtual size_t replace(const T &target, const T *value, size_t valueSize);
//virtual size_t replace(const T &target, const Jupiter::Readable_String<T> &value);
//virtual size_t replace(const T *target, size_t targetSize, const T *value, size_t valueSize);
//virtual size_t replace(const T *target, size_t targetSize, const Jupiter::Readable_String<T> &value);
//virtual size_t replace(const Jupiter::Readable_String<T> &target, const T *value, size_t valueSize);
//virtual size_t replace(const Jupiter::Readable_String<T> &target, const Jupiter::Readable_String<T> &value);
virtual size_t replace(const T *target, size_t targetSize, const T *value, size_t valueSize);
virtual size_t replace(const T *target, size_t targetSize, const Jupiter::Readable_String<T> &value);
virtual size_t replace(const Jupiter::Readable_String<T> &target, const T *value, size_t valueSize);
virtual size_t replace(const Jupiter::Readable_String<T> &target, const Jupiter::Readable_String<T> &value);
/**
* @brief Copies the data from the input string and concatenates it to the end of String.

111
Jupiter/String_Type_Imp.h

@ -258,6 +258,117 @@ template<typename T> size_t Jupiter::String_Type<T>::replace(const Jupiter::Read
return this->replace(target.ptr(), target.size(), value);
}
template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, size_t targetSize, const T *value, size_t valueSize)
{
if (valueSize == 1)
return this->replace(target, targetSize, *value);
if (targetSize != 0)
{
//if (targetSize == 1)
// return this->replace(*target, value, valueSize);
if (targetSize < this->size())
{
if (valueSize > targetSize)
{
size_t instancesSize = 4;
size_t *instances = new size_t[instancesSize];
// pass 1 (count instances)
size_t instanceCount = 0, i = 0, j;
while (i <= this->size() - targetSize)
{
j = 0;
while (this->get(i + j) == target[j])
{
if (++j == targetSize)
{
i += targetSize;
if (instanceCount == instancesSize)
{
size_t *tInstances = new size_t[instancesSize * 2];
for (instanceCount = 0; instanceCount != instancesSize; instanceCount++)
tInstances[instanceCount] = instances[instanceCount];
instancesSize *= 2;
}
instances[instanceCount] = i;
instanceCount++;
break;
}
}
if (j != targetSize)
i++;
}
if (instanceCount != 0)
{
// pass 2 (adjust string and replace values)
size_t endSize = this->size() + (valueSize - targetSize) * instanceCount;
this->setBufferSize(endSize);
instancesSize = endSize; // Repurposing. Now used as just another index.
j = Jupiter::String_Type<T>::length;
while (instanceCount != 0)
{
i = instances[--instanceCount];
while (j != i)
Jupiter::String_Type<T>::str[--instancesSize] = Jupiter::String_Type<T>::str[--j];
j = valueSize;
while (j != 0)
Jupiter::String_Type<T>::str[--instancesSize] = value[--j];
j = i - targetSize;
}
Jupiter::String_Type<T>::length = endSize;
}
delete[] instances;
}
else
{
size_t i = 0, j = 0, k, l;
while (j <= this->size() - targetSize)
{
k = 0;
while (this->get(j + k) == target[k])
{
if (++k == targetSize) // match found
{
for (l = 0; l != valueSize; l++)
Jupiter::String_Type<T>::str[i + l] = value[l];
i += valueSize;
j += k;
break;
}
}
if (k != targetSize)
Jupiter::String_Type<T>::str[i++] = Jupiter::String_Type<T>::str[j++];
}
while (j < this->size())
Jupiter::String_Type<T>::str[i++] = Jupiter::String_Type<T>::str[j++];
Jupiter::String_Type<T>::length = i;
}
}
else if (targetSize == this->size() && this->equals(target, targetSize))
return this->set(value);
}
return Jupiter::String_Type<T>::length;
}
template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, size_t targetSize, const Jupiter::Readable_String<T> &value)
{
return this->replace(target, targetSize, value.ptr(), value.size());
}
template<typename T> size_t Jupiter::String_Type<T>::replace(const Jupiter::Readable_String<T> &target, const T *value, size_t valueSize)
{
return this->replace(target.ptr(), target.size(), value, valueSize);
}
template<typename T> size_t Jupiter::String_Type<T>::replace(const Jupiter::Readable_String<T> &target, const Jupiter::Readable_String<T> &value)
{
return this->replace(target.ptr(), target.size(), value.ptr(), value.size());
}
// concat
template<typename T> size_t Jupiter::String_Type<T>::concat(const Jupiter::Readable_String<T> &in)

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save