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; }
|
||||
|
|
|
|||
|
|
@ -9,6 +9,18 @@ struct TestStruct {
|
|||
String str = "test data";
|
||||
};
|
||||
|
||||
TEST_DEF_STATIC(Addition) {
|
||||
String str1 = "abc";
|
||||
String str2 = "def";
|
||||
{
|
||||
str1 + str2;
|
||||
}
|
||||
{
|
||||
TEST(str1 + str2 == "abcdef");
|
||||
TEST(str1 + "aaaccc" == "abcaaaccc");
|
||||
}
|
||||
}
|
||||
|
||||
TEST_DEF_STATIC(Simple) {
|
||||
String str;
|
||||
TEST(str.getIsConstFlag());
|
||||
|
|
@ -35,4 +47,5 @@ TEST_DEF_STATIC(Simple) {
|
|||
|
||||
TEST_DEF(Strings) {
|
||||
testSimple();
|
||||
testAddition();
|
||||
}
|
||||
|
|
@ -33,78 +33,78 @@ TEST_DEF(calcLength) {
|
|||
|
||||
TEST_DEF(insertLogic_emptyTarget) {
|
||||
// Test insertLogic function with an empty target string
|
||||
char inserted[40] = { "" };
|
||||
const char* cur = "Hello";
|
||||
const char* tar = "";
|
||||
const char* result = "Hello";
|
||||
char* inserted = Logic::insertLogic(cur, tar, 5, 0);
|
||||
Logic::insertLogic(inserted, 40, cur, tar, 5, 0);
|
||||
TEST(Logic::isEqualLogic(inserted, result));
|
||||
delete[] inserted;
|
||||
}
|
||||
|
||||
TEST_DEF(insertLogic_emptyCurrent) {
|
||||
// Test insertLogic function with an empty current string
|
||||
char inserted[40] = { "" };
|
||||
const char* cur = "";
|
||||
const char* tar = "World";
|
||||
const char* result = "World";
|
||||
char* inserted = Logic::insertLogic(cur, tar, 0, 5);
|
||||
Logic::insertLogic(inserted, 40, cur, tar, 0, 5);
|
||||
TEST(Logic::isEqualLogic(inserted, result));
|
||||
delete[] inserted;
|
||||
}
|
||||
|
||||
TEST_DEF(insertLogic_curLengthLessThanPos) {
|
||||
// Test insertLogic function with current length less than the insert position
|
||||
char inserted[40] = { "" };
|
||||
const char* cur = "Hello";
|
||||
const char* tar = "World";
|
||||
const char* result = "HelloWorld";
|
||||
char* inserted = Logic::insertLogic(cur, tar, 10, 5);
|
||||
Logic::insertLogic(inserted, 40, cur, tar, 10, 5);
|
||||
TEST(Logic::isEqualLogic(inserted, result));
|
||||
delete[] inserted;
|
||||
}
|
||||
|
||||
TEST_DEF(removeLogic_emptyCurrent) {
|
||||
// Test removeLogic function with an empty current string
|
||||
char removed[40] = { "" };
|
||||
const char* cur = "";
|
||||
const char* result = "";
|
||||
char* removed = Logic::removeLogic(cur, 0, 0);
|
||||
Logic::removeLogic(removed, 40, cur, 0, 0);
|
||||
TEST(Logic::isEqualLogic(removed, result));
|
||||
delete[] removed;
|
||||
}
|
||||
|
||||
TEST_DEF(removeLogic_removeUntilEnd) {
|
||||
// Test removeLogic function by removing until the end of the current string
|
||||
char removed[40] = { "" };
|
||||
const char* cur = "HelloWorld";
|
||||
const char* result = "World";
|
||||
char* removed = Logic::removeLogic(cur, 0, 5);
|
||||
Logic::removeLogic(removed, 40, cur, 0, 5);
|
||||
TEST(Logic::isEqualLogic(removed, result));
|
||||
delete[] removed;
|
||||
}
|
||||
|
||||
TEST_DEF(removeLogic_removeMiddleCharacters) {
|
||||
// Test removeLogic function by removing characters in the middle of the current string
|
||||
char removed[40] = { "" };
|
||||
const char* cur = "HelloWorld";
|
||||
const char* result = "Helrld";
|
||||
char* removed = Logic::removeLogic(cur, 3, 7);
|
||||
Logic::removeLogic(removed, 40, cur, 3, 7);
|
||||
TEST(Logic::isEqualLogic(removed, result));
|
||||
delete[] removed;
|
||||
}
|
||||
|
||||
TEST_DEF(insertLogicGood) {
|
||||
// Test insertLogic function
|
||||
char inserted[40] = { "" };
|
||||
const char* cur = "Hello";
|
||||
const char* tar = "World";
|
||||
const char* result = "HelloWorld";
|
||||
char* inserted = Logic::insertLogic(cur, tar, 5, 5);
|
||||
Logic::insertLogic(inserted, 40, cur, tar, 5, 5);
|
||||
TEST(Logic::isEqualLogic(inserted, result));
|
||||
delete[] inserted;
|
||||
}
|
||||
|
||||
TEST_DEF(removeLogicGood) {
|
||||
// Test removeLogic function
|
||||
char removed[40] = { "" };
|
||||
const char* cur = "HelloWorld";
|
||||
const char* result = "Helo";
|
||||
char* removed = Logic::removeLogic(cur, 3, 8);
|
||||
Logic::removeLogic(removed, 40, cur, 3, 8);
|
||||
TEST(Logic::isEqualLogic(removed, result));
|
||||
delete[] removed;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue