enhanced index and match

This commit is contained in:
2009-09-17 00:35:29 +00:00
parent 63c12720cb
commit ae7b0a5bdd
9 changed files with 222 additions and 37 deletions

View File

@ -0,0 +1,25 @@
#
# test the third parameter(starting position) of index and match
#
BEGIN {
xstr = "abcdefabcdefabcdef";
xsub = "abc";
xlen = length(xsub);
i = 1;
while ((i = index(xstr, xsub, i)) > 0)
{
print i, substr(xstr, i, xlen);
i += xlen;
}
print "----------------";
i = 1;
while (match(xstr, xsub, i) > 0)
{
print RSTART, substr(xstr, RSTART, RLENGTH);
i = RSTART + RLENGTH;
}
}

View File

@ -1990,6 +1990,35 @@ pq...r AAA2
kbs ddd
dif cccc
--------------------------------------------------------------------------------
../../cmd/awk/.libs/qseawk --newline=on -o- -f lang-038.awk </dev/stdin 2>&1
--------------------------------------------------------------------------------
BEGIN {
xstr = "abcdefabcdefabcdef";
xsub = "abc";
xlen = length (xsub);
i = 1;
while ((i = index (xstr,xsub,i) > 0))
{
print i,substr (xstr,i,xlen);
i += xlen;
}
print "----------------";
i = 1;
while ((match (xstr,xsub,i) > 0))
{
print RSTART,substr (xstr,RSTART,RLENGTH);
i = (RSTART + RLENGTH);
}
}
1 abc
7 abc
13 abc
----------------
1 abc
7 abc
13 abc
--------------------------------------------------------------------------------
../../cmd/awk/.libs/qseawk -f quicksort.awk quicksort.dat </dev/stdin 2>&1
--------------------------------------------------------------------------------

View File

@ -148,6 +148,7 @@ PROGS="
lang-035.awk/lang-035.dat2//--newline=on -o- -vdatafile=lang-035.dat1 -vgroupname=lang-035
lang-036.awk/lang-036.dat//--newline=on -o-
lang-037.awk/lang-037.dat//--newline=on -o-
lang-038.awk///--newline=on -o-
quicksort.awk/quicksort.dat//
quicksort2.awk/quicksort2.dat//