mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-11-26 05:42:07 +00:00
add str.split
This commit is contained in:
parent
db3ba94b5a
commit
6ecf8daef7
2 changed files with 27 additions and 1 deletions
|
@ -2,6 +2,7 @@
|
|||
#include "compat.h"
|
||||
#include "intClass.h"
|
||||
#include "scriptError.h"
|
||||
#include "parser.h"
|
||||
#include <string.h>
|
||||
|
||||
char* getStringValue(Variable_t* var) {
|
||||
|
@ -88,6 +89,28 @@ ClassFunction(stringInEq){
|
|||
return newIntVariablePtr(strcmp(caller->string.value, args[0]->string.value));
|
||||
}
|
||||
|
||||
ClassFunction(stringSplit) {
|
||||
int valLen = strlen(args[0]->string.value);
|
||||
|
||||
char* start = caller->string.value;
|
||||
char* find = NULL;
|
||||
Vector_t arr = newVec(sizeof(char**), 1);
|
||||
char* temp;
|
||||
|
||||
while ((find = (strstr(start, args[0]->string.value))) != NULL) {
|
||||
temp = utils_copyStringSize(start, find - start);
|
||||
vecAdd(&arr, temp);
|
||||
|
||||
start = find + valLen;
|
||||
}
|
||||
|
||||
temp = utils_copyStringSize(start, caller->string.value + strlen(caller->string.value) - start);
|
||||
vecAdd(&arr, temp);
|
||||
|
||||
Variable_t a = { .variableType = StringArrayClass, .solvedArray.vector = arr };
|
||||
return copyVariableToPtr(a);
|
||||
}
|
||||
|
||||
u8 strOneIntArg[] = { IntClass };
|
||||
u8 oneStringArg[] = { StringClass };
|
||||
|
||||
|
@ -100,6 +123,8 @@ ClassFunctionTableEntry_t stringFunctions[] = {
|
|||
{"-", stringMinusInt, 1, strOneIntArg},
|
||||
{"==", stringEq, 1, oneStringArg},
|
||||
{"!=", stringInEq, 1, oneStringArg},
|
||||
{"split", stringSplit, 1, oneStringArg},
|
||||
{"/", stringSplit, 1, oneStringArg},
|
||||
};
|
||||
|
||||
Variable_t getStringMember(Variable_t* var, char* memberName) {
|
||||
|
|
|
@ -13,3 +13,4 @@ typedef struct {
|
|||
void exitStaticVars(Vector_t* v);
|
||||
void exitFunction(Operator_t* start, u32 len);
|
||||
ParserRet_t parseScript(char* in, u32 len);
|
||||
char* utils_copyStringSize(const char* in, int size);
|
Loading…
Reference in a new issue