Changes to MString to add insert and remove methods.
This commit is contained in:
1 parent
88d51cb598
commit
8f8c14d7b2
6 files changed
+103
-1
No files matched your search
+39
@@ -2,6 +2,7 @@
|
||||
#include "Log.h"
|
||||
#include <stdlib.h>
|
||||
#include <iomanip>
|
||||
#include <cstring>
|
||||
|
||||
namespace coreutils {
|
||||
|
||||
@@ -139,6 +140,44 @@ namespace coreutils {
|
||||
return *this;
|
||||
}
|
||||
|
||||
void MString::insert(char ch, int offset) {
|
||||
setSize(length + 1);
|
||||
for(int ix = length; ix >= offset; ix--)
|
||||
getData()[ix + 1] = getData()[ix];
|
||||
data[offset] = ch;
|
||||
}
|
||||
|
||||
void MString::insert(ZString &value, int offset) {
|
||||
setSize(length + value.getLength());
|
||||
for(int ix = length; ix >= offset; ix--)
|
||||
getData()[ix + value.getLength()] = getData()[ix];
|
||||
std::memcpy(data + offset, value.getData(), value.getLength());
|
||||
}
|
||||
|
||||
void MString::insert(std::string value, int offset) {
|
||||
setSize(length + value.size());
|
||||
for(int ix = length; ix >= offset; ix--)
|
||||
getData()[ix + value.size()] = getData()[ix];
|
||||
std::memcpy(data + offset, value.c_str(), value.size());
|
||||
}
|
||||
|
||||
void MString::replace(char ch, int offset) {
|
||||
|
||||
}
|
||||
|
||||
void MString::replace(ZString &value, int offset) {
|
||||
}
|
||||
|
||||
void MString::replace(std::string value, int offset) {
|
||||
}
|
||||
|
||||
void MString::remove(int offset, int length) {
|
||||
// (data + this->length) > (data + offset + length) ? length: length; // TODO: Need to calculate correct length.
|
||||
for(int ix = offset; ix < this->length; ix++)
|
||||
getData()[ix] = getData()[ix + length];
|
||||
setSize(this->length - length);
|
||||
}
|
||||
|
||||
MString& MString::write(char ch) {
|
||||
setSize(length + 1);
|
||||
*(data + length - 1) = ch;
|
||||
|
||||
Reference in new issue
Block a user