diff --git a/Keywords.txt b/Keywords.txt index 39ddc16..cd08620 100644 --- a/Keywords.txt +++ b/Keywords.txt @@ -60,6 +60,7 @@ RTRIM$ SAVEFILE SELECT SHORT +SPLIT SPLITPATH$ STEP STR$ diff --git a/Prototypes.txt b/Prototypes.txt index 085c9e8..7e13fe5 100644 --- a/Prototypes.txt +++ b/Prototypes.txt @@ -13,6 +13,7 @@ REVERSE$ (CSTRING src) RIGHT$ (CSTRING s, INT length) RTRIM$ (CSTRING s) SAVEFILE (CSTRING src, CSTRING fname) +SPLIT (CONSTANT CSTRING input, CONSTANT CSTRING separators, BOOL remove_empty) SPLITPATH$ (CSTRING FPATH, INT mask) TRIM$ (CSTRING s) UCASE$ (CSTRING str) diff --git a/runtime.inc b/runtime.inc index 5056155..109c9c9 100644 --- a/runtime.inc +++ b/runtime.inc @@ -15,9 +15,26 @@ DECLARE FUNCTION CSTRING REVERSE$ (CSTRING); DECLARE FUNCTION CSTRING REPLACE$ (CSTRING subject, CONSTANT CSTRING& search, CONSTANT CSTRING& replace); DECLARE FUNCTION INT VAL (CSTRING); DECLARE FUNCTION CSTRING FORMAT$ (CONSTANT CSTRING &fmt, ...); +DECLARE FUNCTION VECTOR SPLIT (CONSTANT CSTRING input, CONSTANT CSTRING separators, BOOL remove_empty = TRUE); DECLARE SUB PRINT (CSTRING); DECLARE SUB SAVEFILE(CSTRING src, CSTRING fname); +FUNCTION VECTOR SPLIT (CONSTANT CSTRING input, CONSTANT CSTRING separators, BOOL remove_empty) BEGIN + DIM VECTOR lst; + DIM std::ostringstream word; + + FOR (UINT n = 0 TO n < input.size() STEP n++) BEGIN + IF (CSTRING::npos == separators.find(input[n])) THEN + word << input[n]; + ELSE + IF (NOT word.str().empty() OR NOT remove_empty) lst.push_back(word.str()); + word.str(""); + ENDIF + END + IF (NOT word.str().empty() OR NOT remove_empty) lst.push_back(word.str()); + + RETURN lst; +ENDFUNCTION FUNCTION CSTRING FORMAT$ (CONSTANT CSTRING &fmt, ...) BEGIN DIM AS VECTOR str(100,'\0');