'--- Full description available in separate HTML document.
'---------------------------------------------------------------------
FUNCTION ParseLine&
(inpLine$
, sepChars$
, quoChars$
, outArray$
(), minUB&
) '--- option _explicit requirements ---
DIM ilen&
, icnt&
, slen%
, s1%
, s2%
, s3%
, s4%
, s5%
, q1%
, q2%
DIM oalb&
, oaub&
, ocnt&
, flag%
, ch%
, nest%
, spos&
, epos&
'--- so far return nothing ---
ParseLine& = -1
'--- init & check some runtime variables ---
ilen&
= LEN(inpLine$
): icnt&
= 1 IF slen%
> 5 THEN slen%
= 5 'max. 5 chars, ignore the rest oalb&
= LBOUND(outArray$
): oaub&
= UBOUND(outArray$
): ocnt&
= oalb&
'--- skip preceding separators ---
plSkipSepas:
flag% = 0
ch%
= ASC(inpLine$
, icnt&
) CASE 1: flag%
= ch%
<> s1%
CASE 2: flag%
= ch%
<> s1%
AND ch%
<> s2%
CASE 3: flag%
= ch%
<> s1%
AND ch%
<> s2%
AND ch%
<> s3%
CASE 4: flag%
= ch%
<> s1%
AND ch%
<> s2%
AND ch%
<> s3%
AND ch%
<> s4%
CASE 5: flag%
= ch%
<> s1%
AND ch%
<> s2%
AND ch%
<> s3%
AND ch%
<> s4%
AND ch%
<> s5%
icnt& = icnt& + 1
'--- redim to clear array on 1st word/component ---
'--- expand array, if required ---
plNextWord:
oaub& = oaub& + 10
'--- get current word/component until next separator ---
flag% = 0: nest% = 0: spos& = icnt& - 1
nest% = 1
nest% = nest% + 1
nest% = nest% - 1
ch%
= ASC(inpLine$
, icnt&
) CASE 0: flag%
= (nest%
= 0 AND (ch%
= q1%
)) OR (nest%
= 1 AND ch%
= q2%
) CASE 1: flag%
= (nest%
= 0 AND (ch%
= s1%
OR ch%
= q1%
)) OR (nest%
= 1 AND ch%
= q2%
) CASE 2: flag%
= (nest%
= 0 AND (ch%
= s1%
OR ch%
= s2%
OR ch%
= q1%
)) OR (nest%
= 1 AND ch%
= q2%
) CASE 3: flag%
= (nest%
= 0 AND (ch%
= s1%
OR ch%
= s2%
OR ch%
= s3%
OR ch%
= q1%
)) OR (nest%
= 1 AND ch%
= q2%
) CASE 4: flag%
= (nest%
= 0 AND (ch%
= s1%
OR ch%
= s2%
OR ch%
= s3%
OR ch%
= s4%
OR ch%
= q1%
)) OR (nest%
= 1 AND ch%
= q2%
) CASE 5: flag%
= (nest%
= 0 AND (ch%
= s1%
OR ch%
= s2%
OR ch%
= s3%
OR ch%
= s4%
OR ch%
= s5%
OR ch%
= q1%
)) OR (nest%
= 1 AND ch%
= q2%
) icnt& = icnt& + 1
epos& = icnt& - 1
IF ASC(inpLine$
, spos&
) = q1%
THEN spos&
= spos&
+ 1 outArray$
(ocnt&
) = MID$(inpLine$
, spos&
, epos&
- spos&
) ocnt& = ocnt& + 1
'--- more words/components following? ---
IF (ch%
<> q1%
) AND (ch%
<> q2%
OR nest%
= 0) THEN outArray$
(ocnt&
- 1) = outArray$
(ocnt&
- 1) + CHR$(ch%
) '--- final array size adjustment, then exit ---
plEnd:
IF ocnt&
- 1 < minUB&
THEN ocnt&
= minUB&
+ 1 ParseLine& = ocnt& - 1