Adding objects GUI initial. Changing TODO. Some fixes along side
This commit is contained in:
parent
f9d62c324d
commit
112fea2f04
18 changed files with 1345 additions and 56 deletions
|
|
@ -26,42 +26,42 @@ namespace tp {
|
|||
return iter - in;
|
||||
}
|
||||
|
||||
static tChar* insertLogic(const tChar* cur, const tChar* tar, Index at, Index len) {
|
||||
static void insertLogic(tChar* result, Index resultLen, const tChar* cur, const tChar* tar, Index at, Index len) {
|
||||
auto curLen = calcLength(cur);
|
||||
auto allLen = curLen + len;
|
||||
auto* out = new tChar[allLen + 1];
|
||||
ASSERT(allLen <= resultLen);
|
||||
|
||||
DEBUG_ASSERT(curLen >= 0)
|
||||
DEBUG_ASSERT(len >= 0)
|
||||
DEBUG_ASSERT(at < curLen + 1 && at >= 0)
|
||||
|
||||
for (Index idx = 0; idx < at; idx++) {
|
||||
out[idx] = cur[idx];
|
||||
result[idx] = cur[idx];
|
||||
}
|
||||
for (Index idx = 0; idx < len; idx++) {
|
||||
out[idx + at] = tar[idx];
|
||||
result[idx + at] = tar[idx];
|
||||
}
|
||||
for (Index idx = at + len; idx < allLen; idx++) {
|
||||
out[idx] = cur[idx - len];
|
||||
result[idx] = cur[idx - len];
|
||||
}
|
||||
out[allLen] = '\0';
|
||||
return out;
|
||||
result[allLen] = '\0';
|
||||
}
|
||||
|
||||
// including end not including start
|
||||
static tChar* removeLogic(const tChar* cur, Index start, Index end) {
|
||||
static void removeLogic(tChar* result, Index resultLen, const tChar* cur, Index start, Index end) {
|
||||
auto curLen = calcLength(cur);
|
||||
auto rangeLen = end - start;
|
||||
auto newLen = curLen - rangeLen;
|
||||
auto* out = new tChar[newLen + 1];
|
||||
out[newLen] = '\0';
|
||||
|
||||
ASSERT(newLen <= resultLen);
|
||||
|
||||
result[newLen] = '\0';
|
||||
for (Index idx = 0; idx < start; idx++) {
|
||||
out[idx] = cur[idx];
|
||||
result[idx] = cur[idx];
|
||||
}
|
||||
for (Index idx = end; idx < curLen; idx++) {
|
||||
out[idx - rangeLen] = cur[idx];
|
||||
result[idx - rangeLen] = cur[idx];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
static bool isEqualLogic(const tChar* left, const tChar* right) {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace tp {
|
|||
class StringData {
|
||||
friend StringTemplate<tChar>;
|
||||
typedef StringLogic<tChar> Logic;
|
||||
typedef typename StringLogic<tChar>::Index Index;
|
||||
|
||||
private:
|
||||
uint2 mIsConst; // source is non-modifiable
|
||||
|
|
@ -38,7 +39,7 @@ namespace tp {
|
|||
mEditedIdx = 0;
|
||||
}
|
||||
|
||||
explicit StringData(const tChar* aBuff) {
|
||||
explicit StringData(tChar* aBuff) {
|
||||
MODULE_SANITY_CHECK(gModuleStrings)
|
||||
DEBUG_ASSERT(aBuff)
|
||||
auto const len = Logic::calcLength(aBuff);
|
||||
|
|
@ -58,7 +59,7 @@ namespace tp {
|
|||
if (!mIsConst) delete[] mBuff;
|
||||
}
|
||||
|
||||
void resize(ualni size) {
|
||||
void resize(Index size) {
|
||||
DEBUG_ASSERT(mReferenceCount == 1 && !mIsConst)
|
||||
delete[] mBuff;
|
||||
mBuff = new tChar[size + 1];
|
||||
|
|
@ -143,7 +144,7 @@ namespace tp {
|
|||
}
|
||||
|
||||
// output will be null if in TextEditing mode
|
||||
tChar* resize(uint1 size) {
|
||||
tChar* resize(Index size) {
|
||||
makeModifiable();
|
||||
mData->resize(size);
|
||||
return write();
|
||||
|
|
@ -231,6 +232,12 @@ namespace tp {
|
|||
Logic::calcLineOffsets(read(), size(), aOut);
|
||||
}
|
||||
|
||||
StringTemplate& operator=(tChar* in) {
|
||||
this->~StringTemplate();
|
||||
new (this) StringTemplate(in);
|
||||
return *this;
|
||||
}
|
||||
|
||||
StringTemplate& operator=(const tChar* in) {
|
||||
this->~StringTemplate();
|
||||
new (this) StringTemplate(in);
|
||||
|
|
@ -250,6 +257,14 @@ namespace tp {
|
|||
return Logic::isEqualLogic(in.read(), read());
|
||||
}
|
||||
|
||||
StringTemplate operator+(const StringTemplate& in) const {
|
||||
StringTemplate out;
|
||||
auto const newSize = in.size() + size();
|
||||
out.resize(newSize);
|
||||
Logic::insertLogic(out.write(), newSize, read(), in.read(), size(), in.size());
|
||||
return out;
|
||||
}
|
||||
|
||||
public: // Debugging
|
||||
[[nodiscard]] ualni getReferenceCount() const { return mData->mReferenceCount; }
|
||||
[[nodiscard]] bool getIsConstFlag() const { return mData->mIsConst; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue