Code Comments
Programming Forum and web based access to our favorite programming groups.Either put up or shut up. (I believe this is a very usefulness of this
function is self-evident - specification of table can be defined at
beginning by only specifying the delimiter strings.)
Here's my version, "matchCol(s, r, bA)", where s is the source line, r is
regexp spefying delimiter b/w columns; bA[1..] is resultant array of
columns.
--------------
function matchCol(s, r, bA) {
bL=0
if (match(s, r)) {if (RSTART!=1) bA[++bL]= 1}
else bA[++bL]= 1
bL= matchCol2(s, r, bA, 0, bL)
if (bA[bL-1]>bA[bL]) bL-= 2 # if end is regexp
return bL
}
function matchCol2(s, r, bA, posn, bL) {
print "incoming s=" s", bL="bL", bA[bL]="bA[bL]
if (match(s, r)) {
if (bL) bA[++bL]= posn+RSTART-1 # before current regexp
if (bA[bL]+1==bA[bL-1]) bL-= 2 # if regexp is same as last
bA[++bL]= posn+RSTART+RLENGTH # after current regexp
bL= matchCol2(substr(s, RSTART+RLENGTH), r, bA, bA[bL]-1, bL)
}
else bA[++bL]= posn+length(s) # before last regexp
return bL
}
Post Follow-up to this messageA Ferenstein <epaalx@hotmail.com> wrote:
> Either put up or shut up. (I believe this is a very usefulness of this
> function is self-evident - specification of table can be defined at
> beginning by only specifying the delimiter strings.)
>
> Here's my version, "matchCol(s, r, bA)", where s is the source line, r is
> regexp spefying delimiter b/w columns; bA[1..] is resultant array of
> columns.
>
> --------------
>
> function matchCol(s, r, bA) {
> bL=0
> if (match(s, r)) {if (RSTART!=1) bA[++bL]= 1}
> else bA[++bL]= 1
> bL= matchCol2(s, r, bA, 0, bL)
> if (bA[bL-1]>bA[bL]) bL-= 2 # if end is regexp
> return bL
> }
>
> function matchCol2(s, r, bA, posn, bL) {
> print "incoming s=" s", bL="bL", bA[bL]="bA[bL]
> if (match(s, r)) {
> if (bL) bA[++bL]= posn+RSTART-1 # before current regexp
> if (bA[bL]+1==bA[bL-1]) bL-= 2 # if regexp is same as last
> bA[++bL]= posn+RSTART+RLENGTH # after current regexp
> bL= matchCol2(substr(s, RSTART+RLENGTH), r, bA, bA[bL]-1, bL)
> }
> else bA[++bL]= posn+length(s) # before last regexp
> return bL
> }
What does this supposed to do? Your solution doesn't match example you
posted. The count is wrong. Repost.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.