Browse Source

Added some insert() and replace() functions. More will be added.

release/0.19
JustinAJ 11 years ago
parent
commit
f66461231d
  1. 28
      Jupiter/String_Type.h
  2. 97
      Jupiter/String_Type_Imp.h
  3. BIN
      Release/Jupiter.lib

28
Jupiter/String_Type.h

@ -113,6 +113,34 @@ namespace Jupiter
virtual size_t set(const T *in);
virtual size_t set(const T in);
/**
* @brief Inserts data into a position in the string.
*
* @param index Index to insert data to.
* @param value Value to insert.
*/
virtual size_t insert(size_t index, const T &value);
virtual size_t insert(size_t index, const Jupiter::Readable_String<T> &value);
/**
* @brief Replaces all instances of one value with another value.
*
* @param target Target to search for and replace.
* @param value Value to replace the target with.
* @return New size of the string.
*/
virtual size_t replace(const T &target, const T &value);
virtual size_t replace(const T *target, size_t targetSize, const T &value);
virtual size_t replace(const Jupiter::Readable_String<T> &target, const T &value);
//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);
/**
* @brief Copies the data from the input string and concatenates it to the end of String.
*

97
Jupiter/String_Type_Imp.h

@ -163,6 +163,103 @@ template<typename T> size_t Jupiter::String_Type<T>::set(const T in)
return Jupiter::String_Type<T>::length = 1;
}
// replace
template<typename T> size_t Jupiter::String_Type<T>::insert(size_t index, const T &value)
{
if (index >= this->size())
return this->concat(value);
this->setBufferSize(this->size() + 1);
for (size_t i = this->size(); i != index; i--)
Jupiter::String_Type<T>::str[i] = this->get(i-1);
Jupiter::String_Type<T>::str[index] = value;
return ++Jupiter::String_Type<T>::length;
}
template<typename T> size_t Jupiter::String_Type<T>::insert(size_t index, const Jupiter::Readable_String<T> &value)
{
if (index >= this->size())
return this->concat(value);
if (value.size() == 0)
return Jupiter::String_Type<T>::length;
if (value.size() == 1)
return this->insert(index, value.get(0));
this->setBufferSize(this->size() + value.size());
size_t i;
for (i = this->size() + value.size() - 1; i != index + value.size() - 1; i--)
Jupiter::String_Type<T>::str[i] = this->get(i - value.size());
while (i != index)
{
Jupiter::String_Type<T>::str[i] = value.get(i - index);
i--;
}
Jupiter::String_Type<T>::str[index] = value.get(0);
return Jupiter::String_Type<T>::length += value.size();
}
// replace
template<typename T> size_t Jupiter::String_Type<T>::replace(const T &target, const T &value)
{
for (size_t i = 0; i != this->size(); i++)
{
if (this->get(i) == target)
Jupiter::String_Type<T>::str[i] = value;
}
return Jupiter::String_Type<T>::length;
}
template<typename T> size_t Jupiter::String_Type<T>::replace(const T *target, size_t targetSize, const T &value)
{
if (targetSize != 0)
{
if (targetSize == 1)
return this->replace(*target, value);
if (targetSize < this->size())
{
size_t i = 0, j = 0, k;
while (j <= this->size() - targetSize)
{
k = 0;
while (this->get(j + k) == target[k])
{
if (++k == targetSize) // match found
{
Jupiter::String_Type<T>::str[i] = value;
i += 1;
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 Jupiter::Readable_String<T> &target, const T &value)
{
return this->replace(target.ptr(), target.size(), value);
}
// concat
template<typename T> size_t Jupiter::String_Type<T>::concat(const Jupiter::Readable_String<T> &in)
{
size_t nSize = Jupiter::String_Type<T>::length + in.size();

BIN
Release/Jupiter.lib

Binary file not shown.
Loading…
Cancel
Save