Added SPLIT string function

This commit is contained in:
Armando Rivera 2013-11-16 12:33:52 -05:00
parent 4e12a5bae8
commit 51bc040b17
3 changed files with 19 additions and 0 deletions

View File

@ -60,6 +60,7 @@ RTRIM$
SAVEFILE SAVEFILE
SELECT SELECT
SHORT SHORT
SPLIT
SPLITPATH$ SPLITPATH$
STEP STEP
STR$ STR$

View File

@ -13,6 +13,7 @@ REVERSE$ (CSTRING src)
RIGHT$ (CSTRING s, INT length) RIGHT$ (CSTRING s, INT length)
RTRIM$ (CSTRING s) RTRIM$ (CSTRING s)
SAVEFILE (CSTRING src, CSTRING fname) SAVEFILE (CSTRING src, CSTRING fname)
SPLIT (CONSTANT CSTRING input, CONSTANT CSTRING separators, BOOL remove_empty)
SPLITPATH$ (CSTRING FPATH, INT mask) SPLITPATH$ (CSTRING FPATH, INT mask)
TRIM$ (CSTRING s) TRIM$ (CSTRING s)
UCASE$ (CSTRING str) UCASE$ (CSTRING str)

View File

@ -15,9 +15,26 @@ DECLARE FUNCTION CSTRING REVERSE$ (CSTRING);
DECLARE FUNCTION CSTRING REPLACE$ (CSTRING subject, CONSTANT CSTRING& search, CONSTANT CSTRING& replace); DECLARE FUNCTION CSTRING REPLACE$ (CSTRING subject, CONSTANT CSTRING& search, CONSTANT CSTRING& replace);
DECLARE FUNCTION INT VAL (CSTRING); DECLARE FUNCTION INT VAL (CSTRING);
DECLARE FUNCTION CSTRING FORMAT$ (CONSTANT CSTRING &fmt, ...); DECLARE FUNCTION CSTRING FORMAT$ (CONSTANT CSTRING &fmt, ...);
DECLARE FUNCTION VECTOR<CSTRING> SPLIT (CONSTANT CSTRING input, CONSTANT CSTRING separators, BOOL remove_empty = TRUE);
DECLARE SUB PRINT (CSTRING); DECLARE SUB PRINT (CSTRING);
DECLARE SUB SAVEFILE(CSTRING src, CSTRING fname); DECLARE SUB SAVEFILE(CSTRING src, CSTRING fname);
FUNCTION VECTOR<CSTRING> SPLIT (CONSTANT CSTRING input, CONSTANT CSTRING separators, BOOL remove_empty) BEGIN
DIM VECTOR<CSTRING> 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 FUNCTION CSTRING FORMAT$ (CONSTANT CSTRING &fmt, ...) BEGIN
DIM AS VECTOR<char> str(100,'\0'); DIM AS VECTOR<char> str(100,'\0');