Do more progress on refactor

This commit is contained in:
2026-11-21 19:49:01 -06:00
parent 1f3bc13e8d
commit ce19267e35
5 changed files with 352 additions and 285 deletions
+6 -6
View File
@@ -1611,6 +1611,9 @@ class TString : public TByteView {
TObject rhs); TObject rhs);
bool opGreaterThanEqual(InterperterThread *thrd, std::shared_ptr<GC> gc, bool opGreaterThanEqual(InterperterThread *thrd, std::shared_ptr<GC> gc,
TObject rhs); TObject rhs);
bool opExecuteMethod(InterperterThread *thrd, std::shared_ptr<GC> gc,
const std::string &name,
const std::vector<TObject> &args);
public: public:
TString(); TString();
@@ -2240,16 +2243,13 @@ class TYieldEnumerator : public TEnumerator {
class TStringEnumerator : public TEnumerator { class TStringEnumerator : public TEnumerator {
bool hasStarted; bool hasStarted;
size_t index; size_t index;
std::string str; TString *str;
public: public:
TStringEnumerator(std::string str); TStringEnumerator(TString *str);
[[deprecated("Use GCList::Create<T>() instead")]]
static TStringEnumerator *Create(GCList &ls, std::string str);
[[deprecated("Use GCList::Create<T>() instead")]]
static TStringEnumerator *Create(GCList *ls, std::string str);
bool MoveNext(std::shared_ptr<GC> ls); bool MoveNext(std::shared_ptr<GC> ls);
TObject GetCurrent(GCList &ls); TObject GetCurrent(GCList &ls);
void Mark();
}; };
class TListEnumerator : public TEnumerator { class TListEnumerator : public TEnumerator {
+325
View File
@@ -2,6 +2,35 @@
namespace Tesses::CrossLang { namespace Tesses::CrossLang {
#define CROSSLANG_TSTRING_NAMES \
CROSSLANG_TSTRING_NAME_ENT(ToLower) \
CROSSLANG_TSTRING_NAME_ENT(ToUpper) \
CROSSLANG_TSTRING_NAME_ENT(PadLeft) \
CROSSLANG_TSTRING_NAME_ENT(PadRight) \
CROSSLANG_TSTRING_NAME_ENT(Contains) \
CROSSLANG_TSTRING_NAME_ENT(IndexOf) \
CROSSLANG_TSTRING_NAME_ENT(LastIndexOf) \
CROSSLANG_TSTRING_NAME_ENT(GetEnumerator) \
CROSSLANG_TSTRING_NAME_ENT(Substring) \
CROSSLANG_TSTRING_NAME_ENT(Remove) \
CROSSLANG_TSTRING_NAME_ENT(TrimStart) \
CROSSLANG_TSTRING_NAME_ENT(TrimEnd) \
CROSSLANG_TSTRING_NAME_ENT(StartsWith) \
CROSSLANG_TSTRING_NAME_ENT(EndsWith)
enum TStringFuncNameEnum {
#define CROSSLANG_TSTRING_NAME_ENT(name) TSF_##name,
CROSSLANG_TSTRING_NAMES
#undef CROSSLANG_TSTRING_NAME_ENT
}; // namespace Tesses::CrossLang
static std::unordered_map<std::string_view, TStringFuncNameEnum>
string_func_names = {
#define CROSSLANG_TSTRING_NAME_ENT(name) {#name, TSTF_##name},
CROSSLANG_TSTRING_NAMES
#undef CROSSLANG_TSTRING_NAME_ENT
};
TString::TString() {} TString::TString() {}
TString::TString(std::string_view str) : text(str) {} TString::TString(std::string_view str) : text(str) {}
TString::TString(const char *text, size_t len) : text(text, len) {} TString::TString(const char *text, size_t len) : text(text, len) {}
@@ -101,6 +130,302 @@ bool TString::opGreaterThanEqual(InterperterThread *thrd,
thrd->call_stack_entries.back()->Push(gc, Undefined()); thrd->call_stack_entries.back()->Push(gc, Undefined());
return false; return false;
} }
bool TString::opExecuteMethod(InterperterThread *thrd, std::shared_ptr<GC> gc,
const std::string &name,
const std::vector<TObject> &args) {
auto result = string_func_names.find(name);
if (result == string_func_names.end())
return TByteView::opExecuteMethod(thrd, gc, name, args);
switch (result->second) {
case TSF_ToLower: {
std::string str = this->text;
for (size_t i = 0; i < str.size(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
str[i] = 'a' + (str[i] - 'A');
}
}
GCList ls(gc);
thrd->call_stack_entries.back()->Push(gc, ls.Create<TString>(str));
return false;
}
case TSF_ToUpper: {
std::string str = this->text;
for (size_t i = 0; i < str.size(); i++) {
if (str[i] >= 'a' && str[i] <= 'z') {
str[i] = 'A' + (str[i] - 'a');
}
}
GCList ls(gc);
thrd->call_stack_entries.back()->Push(gc, ls.Create<TString>(str));
return false;
}
case TSF_PadLeft: {
std::string str = this->text;
int64_t pad;
char padChar = ' ';
if (args.size() == 0 || args.size() > 2) {
throw VMException(
"String.PadLeft must only accept 1 or 2 arguments");
}
if (GetArgument(args, 0, pad)) {
if ((size_t)pad < str.size()) {
thrd->call_stack_entries.back()->Push(gc, str);
return false;
}
GetArgument(args, 1, padChar);
size_t diff = (size_t)pad - str.size();
str.insert(str.begin(), diff, padChar);
thrd->call_stack_entries.back()->Push(gc, str);
return false;
} else
throw VMException("String.PadLeft must have a long for width");
}
case TSF_PadRight: {
std::string str = this->text;
int64_t pad;
char padChar = ' ';
if (args.size() == 0 || args.size() > 2) {
throw VMException(
"String.PadRight must only accept 1 or 2 arguments");
}
if (GetArgument(args, 0, pad)) {
if ((size_t)pad < str.size()) {
thrd->call_stack_entries.back()->Push(gc, str);
return false;
}
GetArgument(args, 1, padChar);
size_t diff = (size_t)pad - str.size();
str.insert(str.end(), diff, padChar);
thrd->call_stack_entries.back()->Push(gc, str);
return false;
} else
throw VMException("String.PadRight must have a long for width");
}
case TSF_Contains: {
std::string str = this->text;
TString *str2;
char c;
if (GetArgumentHeap(args, 0, str2)) {
int64_t index = 0;
GetArgument(args, 1, index);
auto res = str.find(str2->text, (std::size_t)index);
thrd->call_stack_entries.back()->Push(gc, res != std::string::npos);
return false;
}
else if (GetArgument<char>(args, 0, c)) {
int64_t index = 0;
GetArgument(args, 1, index);
auto res = str.find_first_of(c, (std::size_t)index);
thrd->call_stack_entries.back()->Push(gc, res != std::string::npos);
return false;
}
thrd->call_stack_entries.back()->Push(gc, nullptr);
return false;
}
case TSF_IndexOf: {
std::string str = this->text;
TString *str2;
char c;
if (GetArgumentHeap(args, 0, str2)) {
int64_t index = 0;
GetArgument(args, 1, index);
auto res = str.find(str2->text, (std::size_t)index);
if (res == std::string::npos)
thrd->call_stack_entries.back()->Push(gc, (int64_t)-1);
else
thrd->call_stack_entries.back()->Push(gc, (int64_t)res);
return false;
}
else if (GetArgument<char>(args, 0, c)) {
int64_t index = 0;
GetArgument(args, 1, index);
auto res = str.find_first_of(c, (std::size_t)index);
if (res == std::string::npos)
thrd->call_stack_entries.back()->Push(gc, (int64_t)-1);
else
thrd->call_stack_entries.back()->Push(gc, (int64_t)res);
return false;
}
thrd->call_stack_entries.back()->Push(gc, nullptr);
return false;
}
case TSF_LastIndexOf: {
std::string str = this->text;
TString *str2;
char c;
if (GetArgument(args, 0, str2)) {
int64_t index = str.size();
GetArgument(args, 1, index);
auto res = str.rfind(str2->text, (std::size_t)index);
if (res == std::string::npos)
thrd->call_stack_entries.back()->Push(gc, (int64_t)-1);
else
thrd->call_stack_entries.back()->Push(gc, (int64_t)res);
return false;
} else if (GetArgument<char>(args, 0, c)) {
int64_t index = str.size();
GetArgument(args, 1, index);
auto res = str.find_last_of(c, (std::size_t)index);
if (res == std::string::npos)
thrd->call_stack_entries.back()->Push(gc, (int64_t)-1);
else
thrd->call_stack_entries.back()->Push(gc, (int64_t)res);
return false;
}
thrd->call_stack_entries.back()->Push(gc, nullptr);
return false;
}
case TSF_GetEnumerator: {
GCList ls(gc);
thrd->call_stack_entries.back()->Push(
gc, ls.Create<TStringEnumerator>(this));
return false;
}
case TSF_Substring: {
std::string str = this->text;
if (args.size() >= 1 && std::holds_alternative<int64_t>(args[0])) {
size_t offset = (size_t)std::get<int64_t>(args[0]);
size_t count = std::string::npos;
if (args.size() == 2 && std::holds_alternative<int64_t>(args[1])) {
count = (size_t)std::get<int64_t>(args[1]);
}
GCList ls(gc);
thrd->call_stack_entries.back()->Push(
gc, ls.Create<TString>(str.substr(offset, count)));
return false;
}
thrd->call_stack_entries.back()->Push(gc, nullptr);
return false;
}
case TSF_Remove: {
std::string str = this->text;
if (args.size() >= 1 && std::holds_alternative<int64_t>(args[0])) {
size_t offset = (size_t)std::get<int64_t>(args[0]);
size_t count = std::string::npos;
if (args.size() == 2 && std::holds_alternative<int64_t>(args[1])) {
count = (size_t)std::get<int64_t>(args[1]);
}
GCList ls(gc);
thrd->call_stack_entries.back()->Push(
gc, ls.Create<TString>(str.erase(offset, count)));
return false;
}
thrd->call_stack_entries.back()->Push(gc, nullptr);
return false;
}
case TSF_TrimStart: {
std::string str = this->text;
if (args.size() >= 0) {
char c = (args.size() == 1 && std::holds_alternative<char>(args[0]))
? std::get<char>(args[0])
: ' ';
size_t i = 0;
for (; i < str.size(); i++) {
if (str[i] != c)
break;
}
GCList ls(gc);
thrd->call_stack_entries.back()->Push(
gc, ls.Create<TString>(
(!str.empty() && i < str.size()) ? str.substr(i) : ""));
return false;
}
thrd->call_stack_entries.back()->Push(gc, nullptr);
return false;
}
case TSF_TrimEnd: {
std::string str = this->text;
if (args.size() >= 0) {
char c = (args.size() == 1 && std::holds_alternative<char>(args[0]))
? std::get<char>(args[0])
: ' ';
size_t i = str.size() - 1;
for (; i >= 0; i--) {
if (str[i] != c)
break;
}
GCList ls(gc);
thrd->call_stack_entries.back()->Push(
gc, ls.Create<TString>((!str.empty() && i < str.size())
? str.substr(0, i + 1)
: ""));
return false;
}
thrd->call_stack_entries.back()->Push(gc, nullptr);
return false;
}
case TSF_StartsWith: {
std::string str = this->text;
TString *v;
if (GetArgumentHeap(args, 0, v)) {
if (str.size() < v->text.size()) {
thrd->call_stack_entries.back()->Push(gc, false);
return false;
}
for (size_t i = 0; i < v->text.size(); i++) {
if (v->text[i] != str[i]) {
thrd->call_stack_entries.back()->Push(gc, false);
return false;
}
}
thrd->call_stack_entries.back()->Push(gc, true);
return false;
}
thrd->call_stack_entries.back()->Push(gc, false);
return false;
}
case TSF_EndsWith: {
std::string str = this->text;
TString *v;
if (GetArgumentHeap(args, 0, v)) {
if (str.size() < v->text.size()) {
thrd->call_stack_entries.back()->Push(gc, false);
return false;
}
size_t _end = str.size() - v->text.size();
for (size_t i = 0; i < v->text.size(); i++) {
if (v->text[i] != str[i + _end]) {
thrd->call_stack_entries.back()->Push(gc, false);
return false;
}
}
thrd->call_stack_entries.back()->Push(gc, true);
return false;
}
thrd->call_stack_entries.back()->Push(gc, false);
return false;
}
}
}
bool TString::IsEqualTo(std::shared_ptr<GC> gc, TObject rhs) { bool TString::IsEqualTo(std::shared_ptr<GC> gc, TObject rhs) {
TString *rStr; TString *rStr;
if (GetObjectHeap(rhs, rStr)) { if (GetObjectHeap(rhs, rStr)) {
+16 -15
View File
@@ -92,15 +92,15 @@ TCustomEnumerator *TCustomEnumerator::Create(GCList &ls, TDictionary *dict) {
return ls.Create<TCustomEnumerator>(dict); return ls.Create<TCustomEnumerator>(dict);
} }
TEnumerator *TEnumerator::CreateFromObject(GCList &ls, TObject obj) { TEnumerator *TEnumerator::CreateFromObject(GCList &ls, TObject obj) {
std::string str; TString *str;
TList *mls; TList *mls;
TDynamicList *dynList; TDynamicList *dynList;
TDynamicDictionary *dynDict; TDynamicDictionary *dynDict;
TDictionary *dict; TDictionary *dict;
TEnumerator *enumerator; TEnumerator *enumerator;
TQueryable *q; TQueryable *q;
if (GetObject(obj, str)) { if (GetObjectHeap(obj, str)) {
return TStringEnumerator::Create(ls, str); return ls.Create<TStringEnumerator>(str);
} else if (GetObjectHeap(obj, mls)) { } else if (GetObjectHeap(obj, mls)) {
return TListEnumerator::Create(ls, mls); return TListEnumerator::Create(ls, mls);
} else if (GetObjectHeap(obj, dynList)) { } else if (GetObjectHeap(obj, dynList)) {
@@ -283,32 +283,33 @@ void TDynamicListEnumerator::Mark() {
this->marked = true; this->marked = true;
this->ls->Mark(); this->ls->Mark();
} }
TStringEnumerator::TStringEnumerator(std::string str) TStringEnumerator::TStringEnumerator(TString *str)
: str(str), hasStarted(false) {} : str(str), hasStarted(false) {}
TStringEnumerator *TStringEnumerator::Create(GCList &ls, std::string str) {
return ls.Create<TStringEnumerator>(str);
}
TStringEnumerator *TStringEnumerator::Create(GCList *ls, std::string str) {
return ls->Create<TStringEnumerator>(str);
}
bool TStringEnumerator::MoveNext(std::shared_ptr<GC> ls) { bool TStringEnumerator::MoveNext(std::shared_ptr<GC> ls) {
if (!this->hasStarted) { if (!this->hasStarted) {
this->hasStarted = true; this->hasStarted = true;
this->index = 0; this->index = 0;
return !this->str.empty(); return !this->str->GetString().empty();
} else { } else {
if (this->index >= this->str.size()) if (this->index >= this->str->GetString().size())
return false; return false;
this->index++; this->index++;
return this->index < this->str.size(); return this->index < this->str->GetString().size();
} }
} }
TObject TStringEnumerator::GetCurrent(GCList &ls) { TObject TStringEnumerator::GetCurrent(GCList &ls) {
if (!this->hasStarted) if (!this->hasStarted)
return nullptr; return nullptr;
if (this->index < this->str.size()) if (this->index < this->str->GetString().size())
return this->str[this->index]; return this->str->GetString()[this->index];
return nullptr; return nullptr;
} }
void TStringEnumerator::Mark() {
if (this->marked)
return;
this->marked = true;
this->str->Mark();
}
}; // namespace Tesses::CrossLang }; // namespace Tesses::CrossLang
+4 -8
View File
@@ -111,10 +111,6 @@ TObject TDynamicList::SetAt(GCList &ls, int64_t index, TObject val) {
TDynamicList::~TDynamicList() {} TDynamicList::~TDynamicList() {}
TByteArray *TByteArray::Create(GCList &ls) { return ls.Create<TByteArray>(); }
TByteArray *TByteArray::Create(GCList *ls) { return ls->Create<TByteArray>(); }
void TList::Add(TObject value) { this->items.push_back(value); } void TList::Add(TObject value) { this->items.push_back(value); }
void TList::Set(int64_t index, TObject value) { void TList::Set(int64_t index, TObject value) {
if (index >= 0 && index < this->Count()) { if (index >= 0 && index < this->Count()) {
@@ -209,7 +205,7 @@ bool TList::opExecuteMethod(InterperterThread *thrd, std::shared_ptr<GC> gc,
for (int64_t i = 0; i < this->Count(); i++) { for (int64_t i = 0; i < this->Count(); i++) {
auto item = this->Get(i); auto item = this->Get(i);
gc->BarrierEnd(); gc->BarrierEnd();
if (Equals(gc, args[0], item)) { if (ObjectEquals(gc, args[0], item)) {
cse.back()->Push(gc, true); cse.back()->Push(gc, true);
return false; return false;
} }
@@ -232,7 +228,7 @@ bool TList::opExecuteMethod(InterperterThread *thrd, std::shared_ptr<GC> gc,
for (; i < this->Count(); i++) { for (; i < this->Count(); i++) {
auto item = this->Get(i); auto item = this->Get(i);
gc->BarrierEnd(); gc->BarrierEnd();
if (Equals(gc, args[0], item)) { if (ObjectEquals(gc, args[0], item)) {
cse.back()->Push(gc, i); cse.back()->Push(gc, i);
return false; return false;
@@ -252,7 +248,7 @@ bool TList::opExecuteMethod(InterperterThread *thrd, std::shared_ptr<GC> gc,
for (int64_t i = 0; i < this->Count(); i++) { for (int64_t i = 0; i < this->Count(); i++) {
auto item = this->Get(i); auto item = this->Get(i);
gc->BarrierEnd(); gc->BarrierEnd();
if (Equals(gc, args[0], item)) { if (ObjectEquals(gc, args[0], item)) {
gc->BarrierBegin(); gc->BarrierBegin();
this->RemoveAt(i); this->RemoveAt(i);
i--; i--;
@@ -271,7 +267,7 @@ bool TList::opExecuteMethod(InterperterThread *thrd, std::shared_ptr<GC> gc,
for (int64_t i = 0; i < this->Count(); i++) { for (int64_t i = 0; i < this->Count(); i++) {
auto item = this->Get(i); auto item = this->Get(i);
gc->BarrierEnd(); gc->BarrierEnd();
if (Equals(gc, args[0], item)) { if (ObjectEquals(gc, args[0], item)) {
gc->BarrierBegin(); gc->BarrierBegin();
this->RemoveAt(i); this->RemoveAt(i);
gc->BarrierEnd(); gc->BarrierEnd();
+1 -256
View File
@@ -379,262 +379,7 @@ bool InterperterThread::ExecuteMethod2(std::shared_ptr<GC> gc, TObject instance,
} }
} else if (std::holds_alternative<std::string>(instance)) { } else if (std::holds_alternative<std::string>(instance)) {
std::string str = std::get<std::string>(instance); std::string str = std::get<std::string>(instance);
if (key == "ToLower") {
for (size_t i = 0; i < str.size(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z') {
str[i] = 'a' + (str[i] - 'A');
}
}
cse.back()->Push(gc, str);
return false;
}
if (key == "ToUpper") {
for (size_t i = 0; i < str.size(); i++) {
if (str[i] >= 'a' && str[i] <= 'z') {
str[i] = 'A' + (str[i] - 'a');
}
}
cse.back()->Push(gc, str);
return false;
}
if (key == "PadLeft") {
int64_t pad;
char padChar = ' ';
if (args.size() == 0 || args.size() > 2) {
throw VMException(
"String.PadLeft must only accept 1 or 2 arguments");
}
if (GetArgument(args, 0, pad)) {
if ((size_t)pad < str.size()) {
cse.back()->Push(gc, str);
return false;
}
GetArgument(args, 1, padChar);
size_t diff = (size_t)pad - str.size();
str.insert(str.begin(), diff, padChar);
cse.back()->Push(gc, str);
return false;
} else
throw VMException(
"String.PadLeft must have a long for width");
}
if (key == "PadRight") {
int64_t pad;
char padChar = ' ';
if (args.size() == 0 || args.size() > 2) {
throw VMException(
"String.PadRight must only accept 1 or 2 arguments");
}
if (GetArgument(args, 0, pad)) {
if ((size_t)pad < str.size()) {
cse.back()->Push(gc, str);
return false;
}
GetArgument(args, 1, padChar);
size_t diff = (size_t)pad - str.size();
str.insert(str.end(), diff, padChar);
cse.back()->Push(gc, str);
return false;
} else
throw VMException(
"String.PadRight must have a long for width");
}
if (key == "Contains") {
std::string str2;
char c;
if (GetArgument(args, 0, str2)) {
int64_t index = 0;
GetArgument(args, 1, index);
auto res = str.find(str2, (std::size_t)index);
cse.back()->Push(gc, res != std::string::npos);
return false;
}
else if (GetArgument<char>(args, 0, c)) {
int64_t index = 0;
GetArgument(args, 1, index);
auto res = str.find_first_of(c, (std::size_t)index);
cse.back()->Push(gc, res != std::string::npos);
return false;
}
cse.back()->Push(gc, nullptr);
return false;
}
if (key == "IndexOf") {
std::string str2;
char c;
if (GetArgument(args, 0, str2)) {
int64_t index = 0;
GetArgument(args, 1, index);
auto res = str.find(str2, (std::size_t)index);
if (res == std::string::npos)
cse.back()->Push(gc, (int64_t)-1);
else
cse.back()->Push(gc, (int64_t)res);
return false;
}
else if (GetArgument<char>(args, 0, c)) {
int64_t index = 0;
GetArgument(args, 1, index);
auto res = str.find_first_of(c, (std::size_t)index);
if (res == std::string::npos)
cse.back()->Push(gc, (int64_t)-1);
else
cse.back()->Push(gc, (int64_t)res);
return false;
}
cse.back()->Push(gc, nullptr);
return false;
}
if (key == "LastIndexOf") {
std::string str2;
char c;
if (GetArgument(args, 0, str2)) {
int64_t index = str.size();
GetArgument(args, 1, index);
auto res = str.rfind(str2, (std::size_t)index);
if (res == std::string::npos)
cse.back()->Push(gc, (int64_t)-1);
else
cse.back()->Push(gc, (int64_t)res);
return false;
} else if (GetArgument<char>(args, 0, c)) {
int64_t index = str.size();
GetArgument(args, 1, index);
auto res = str.find_last_of(c, (std::size_t)index);
if (res == std::string::npos)
cse.back()->Push(gc, (int64_t)-1);
else
cse.back()->Push(gc, (int64_t)res);
return false;
}
cse.back()->Push(gc, nullptr);
return false;
}
if (key == "GetEnumerator") {
cse.back()->Push(gc, TStringEnumerator::Create(ls, str));
return false;
}
if (key == "Substring") {
if (args.size() >= 1 &&
std::holds_alternative<int64_t>(args[0])) {
size_t offset = (size_t)std::get<int64_t>(args[0]);
size_t count = std::string::npos;
if (args.size() == 2 &&
std::holds_alternative<int64_t>(args[1])) {
count = (size_t)std::get<int64_t>(args[1]);
}
cse.back()->Push(gc, str.substr(offset, count));
return false;
}
}
if (key == "Remove") {
if (args.size() >= 1 &&
std::holds_alternative<int64_t>(args[0])) {
size_t offset = (size_t)std::get<int64_t>(args[0]);
size_t count = std::string::npos;
if (args.size() == 2 &&
std::holds_alternative<int64_t>(args[1])) {
count = (size_t)std::get<int64_t>(args[1]);
}
cse.back()->Push(gc, str.erase(offset, count));
return false;
}
}
if (key == "TrimStart") {
if (args.size() >= 0) {
char c = (args.size() == 1 &&
std::holds_alternative<char>(args[0]))
? std::get<char>(args[0])
: ' ';
size_t i = 0;
for (; i < str.size(); i++) {
if (str[i] != c)
break;
}
cse.back()->Push(gc, (!str.empty() && i < str.size())
? str.substr(i)
: "");
return false;
}
}
if (key == "TrimEnd") {
if (args.size() >= 0) {
char c = (args.size() == 1 &&
std::holds_alternative<char>(args[0]))
? std::get<char>(args[0])
: ' ';
size_t i = str.size() - 1;
for (; i >= 0; i--) {
if (str[i] != c)
break;
}
cse.back()->Push(gc, (!str.empty() && i < str.size())
? str.substr(0, i + 1)
: "");
return false;
}
}
if (key == "EndsWith") {
std::string v;
if (GetArgument(args, 0, v)) {
if (str.size() < v.size()) {
cse.back()->Push(gc, false);
return false;
}
size_t _end = str.size() - v.size();
for (size_t i = 0; i < v.size(); i++) {
if (v[i] != str[i + _end]) {
cse.back()->Push(gc, false);
return false;
}
}
cse.back()->Push(gc, true);
return false;
}
cse.back()->Push(gc, false);
return false;
}
if (key == "StartsWith") {
std::string v;
if (GetArgument(args, 0, v)) {
if (str.size() < v.size()) {
cse.back()->Push(gc, false);
return false;
}
for (size_t i = 0; i < v.size(); i++) {
if (v[i] != str[i]) {
cse.back()->Push(gc, false);
return false;
}
}
cse.back()->Push(gc, true);
return false;
}
cse.back()->Push(gc, false);
return false;
}
if (key == "Escape") { if (key == "Escape") {
bool quote; bool quote;
if (!GetArgument(args, 0, quote)) if (!GetArgument(args, 0, quote))
@@ -704,7 +449,7 @@ bool InterperterThread::ExecuteMethod2(std::shared_ptr<GC> gc, TObject instance,
size_t index = (size_t)std::get<int64_t>(args[0]); size_t index = (size_t)std::get<int64_t>(args[0]);
size_t sz = str.size(); size_t sz = str.size();
if (index >= 0 && index < sz) { if (index < sz) {
cse.back()->Push(gc, str[index]); cse.back()->Push(gc, str[index]);
return false; return false;
} }