Functions | |
endif | if (nargin< 2||isempty(delim)) delim |
endif | if (isempty(str)) tok |
elseif (length(delim) > 3) start | |
while (start<=len) if(all(str(start)! | |
while (stop<=len) if(any(str(stop) | |
else | if (length(delim)==1) idx |
elseif (length(delim)==2) idx | |
endif | if (isempty(idx)) tok |
if (isempty(skip)) tok | |
endif endif endif endfunction!demo | !strtok ("this is the life")%!%split at the first space |
!printf ("<%s>", t) | |
!if | isempty (s) |
endif | !printf ("<%s>", s(1)) |
!endwhile | !printf ("\n") |
id | is: (strtok(""assert) |
!assert (strtok("this"),"this") | |
!assert (strtok("this "),"this") | |
!assert (strtok("this is"),"this") | |
!assert (strtok(" this"),"this") | |
!assert (strtok(" this "),"this") | |
!assert (strtok(" "),""(1:0)) | |
assert (r,"") | |
assert (r, char(zeros(1, 0))) | |
assert (r," ") | |
assert (r," is") | |
!assert (strtok("this is","i "),"th") | |
!assert (strtok("this is","ij "),"th") | |
!assert (strtok("","jkl "),"") | |
!assert (strtok("this","jkl "),"this") | |
!assert (strtok("this ","jkl "),"this") | |
!assert (strtok("this is","jkl "),"this") | |
!assert (strtok(" this","jkl "),"this") | |
!assert (strtok(" this ","jkl "),"this") | |
!assert (strtok(" ","jkl "),""(1:0)) | |
!assert (strtok(" this "'),"this"') | |
!assert (strtok(" this "',"jkl "),"this"') | |
!assert (t,"beg") | |
Variables | |
function [tok, rem] | |
len = length (str) | |
endwhile | stop = start |
endwhile | tok = str(start:stop-1) |
rem = str(stop:len) | |
else | idx = find (str == delim(1) | str == delim(2) | str == delim(3)) |
else | skip = find (idx(:)' != 1:length(idx)) |
endif endif endif endfunction!demo returning this!demo | !s |
!if | break |
!test [t, r] = strtok("") | |
!test!for | ch |
!assert | ( | t | , | |
"beg" | ||||
) |
!assert | ( | strtok(" this "',"jkl ") | , | |
"this"' | ||||
) |
!assert | ( | strtok(" this "') | , | |
"this"' | ||||
) |
!assert | ( | strtok(" ","jkl ") | , | |
"" | 1:0 | |||
) |
!assert | ( | strtok(" this ","jkl ") | , | |
"this" | ||||
) |
!assert | ( | strtok(" this","jkl ") | , | |
"this" | ||||
) |
!assert | ( | strtok("this is","jkl ") | , | |
"this" | ||||
) |
!assert | ( | strtok("this ","jkl ") | , | |
"this" | ||||
) |
!assert | ( | strtok("this","jkl ") | , | |
"this" | ||||
) |
!assert | ( | strtok("","jkl ") | , | |
"" | ||||
) |
!assert | ( | strtok("this is","ij ") | , | |
"th" | ||||
) |
!assert | ( | strtok("this is","i ") | , | |
"th" | ||||
) |
!assert | ( | strtok(" ") | , | |
"" | 1:0 | |||
) |
!assert | ( | strtok(" this ") | , | |
"this" | ||||
) |
!assert | ( | strtok(" this") | , | |
"this" | ||||
) |
!assert | ( | strtok("this is") | , | |
"this" | ||||
) |
!assert | ( | strtok("this ") | , | |
"this" | ||||
) |
!assert | ( | strtok("this") | , | |
"this" | ||||
) |
! endwhile !printf | ( | "\n" | ) |
endif !printf | ( | "<%s>" | , | |
s(1) | ||||
) |
!printf | ( | "<%s>" | , | |
t | ||||
) |
endif endif endif endfunction !demo !strtok | ( | "this is the life" | ) |
assert | ( | r | , | |
" is" | ||||
) |
assert | ( | r | , | |
" " | ||||
) |
assert | ( | r | , | |
char(zeros(1, 0)) | ||||
) |
assert | ( | r | , | |
"" | ||||
) |
elseif | ( | length(delim) | = =2 |
) |
elseif | ( | length(delim) | , | |
3 | ||||
) |
if | ( | isempty(skip) | ) |
endif if | ( | isempty(idx) | ) |
endif if | ( | isempty(str) | ) |
endif if | ( | ) |
id is: | ( | ) | [virtual] |
! if isempty | ( | s | ) |
while | ( | stop<= | len | ) |
while | ( | start<= | len | ) |
endif endif endif endfunction !demo returning this !demo !s |
!test[t, r] = strtok("") |
! if break |
len = length (str) |
rem = str(stop:len) |