made match() to accept up to 3 arguments only while keeping str::match() extended with up to 4 arguments
This commit is contained in:
parent
0603e3b1ba
commit
5830d8f9ed
12
README.md
12
README.md
@ -15,7 +15,7 @@ At its core, `Hawk` largely supports all the fundamental features of `AWK`, ensu
|
||||
|
||||
1. Pattern-Action Statements: Hawk operates on a series of pattern-action statements. Each statement consists of a pattern that matches input records and an associated action that is executed when the pattern matches.
|
||||
1. Record Processing: Hawk processes input data by splitting it into records and fields. Records are typically lines in a file, while fields are segments of each record separated by a field separator (by default, whitespace). This enables powerful text processing capabilities.
|
||||
1. Built-in Variables: Hawk provides a set of built-in variables that facilitate data manipulation. Commonly used variables include NF (number of fields in the current record), NR (current record number), and $n (the value of the nth field in the current record).
|
||||
1. Built-in Variables: Hawk provides a set of built-in variables that facilitate data manipulation. Commonly used variables include `NF` (number of fields in the current record), `NR` (current record number), and `$n` (the value of the nth field in the current record).
|
||||
1. Built-in Functions: Hawk offers a rich set of built-in functions to perform various operations on data. These functions include string manipulation, numeric calculations, regular expression matching, and more. You can harness their power to transform and analyze your input data effectively.
|
||||
1. Output Formatting: Hawk provides flexible control over the formatting and presentation of output. You can customize the field and record separators, control the output field width, and apply formatting rules to align columns.
|
||||
|
||||
@ -62,7 +62,7 @@ BEGIN { @local a; a = 10; } # syntax ok - a is declared before use.
|
||||
|
||||
### @include and @include_once
|
||||
|
||||
The @include directive inserts the contents of the file specified in the following string as if they appeared in the source stream being processed.
|
||||
The `@include` directive inserts the contents of the file specified in the following string as if they appeared in the source stream being processed.
|
||||
|
||||
Assuming the `hello.inc` file contains the print_hello() function as shown below,
|
||||
|
||||
@ -77,9 +77,9 @@ You may include the the file and use the function.
|
||||
BEGIN { print_hello(); }
|
||||
```
|
||||
|
||||
The semicolon after the included file name is optional. You could write @include "hello.inc" without the ending semicolon.
|
||||
The semicolon after the included file name is optional. You could write `@include "hello.inc"` without the ending semicolon.
|
||||
|
||||
@include_once is similar to @include except it doesn't include the same file multiple times.
|
||||
`@include_once` is similar to `@include` except it doesn't include the same file multiple times.
|
||||
|
||||
```
|
||||
@include_once "hello.inc";
|
||||
@ -234,7 +234,7 @@ Hawk supports various modules.
|
||||
- hawk::GC_NUM_GENS
|
||||
|
||||
#### String
|
||||
The *str* module provides an extensive set of string manipulation functions.
|
||||
The `str` module provides an extensive set of string manipulation functions.
|
||||
|
||||
- str::fromcharcode
|
||||
- str::gsub - equivalent to gsub
|
||||
@ -253,7 +253,7 @@ The *str* module provides an extensive set of string manipulation functions.
|
||||
- str::isxdigit
|
||||
- str::length - equivalent to length
|
||||
- str::ltrim
|
||||
- str::match - equivalent to match
|
||||
- str::match - similar to match. the optional third argument is the search start index. the optional fourth argument is equivalent to the thrid argument to match().
|
||||
- str::normspace
|
||||
- str::printf - equivalent to sprintf
|
||||
- str::rindex
|
||||
|
109
lib/fnc.c
109
lib/fnc.c
@ -29,6 +29,7 @@ static int fnc_fflush (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi);
|
||||
static int fnc_int (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi);
|
||||
static int fnc_asort (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi);
|
||||
static int fnc_asorti (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi);
|
||||
static int fnc_match (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi);
|
||||
|
||||
#define A_MAX HAWK_TYPE_MAX(hawk_oow_t)
|
||||
|
||||
@ -61,7 +62,7 @@ static hawk_fnc_t sysfnctab[] =
|
||||
{ {HAWK_T("gsub"), 4}, 0, { {2, 3, HAWK_T("xvr")}, hawk_fnc_gsub, 0 }, HAWK_NULL},
|
||||
{ {HAWK_T("index"), 5}, 0, { {2, 3, HAWK_NULL}, hawk_fnc_index, 0 }, HAWK_NULL},
|
||||
{ {HAWK_T("length"), 6}, 1, { {0, 1, HAWK_NULL}, hawk_fnc_length, 0 }, HAWK_NULL},
|
||||
{ {HAWK_T("match"), 5}, 0, { {2, 4, HAWK_T("vxvr")}, hawk_fnc_match, 0 }, HAWK_NULL},
|
||||
{ {HAWK_T("match"), 5}, 0, { {2, 3, HAWK_T("vxr")}, fnc_match, 0 }, HAWK_NULL},
|
||||
{ {HAWK_T("split"), 5}, 0, { {2, 3, HAWK_T("vrx")}, hawk_fnc_split, 0 }, HAWK_NULL},
|
||||
{ {HAWK_T("sprintf"), 7}, 0, { {1, A_MAX, HAWK_NULL}, hawk_fnc_sprintf, 0 }, HAWK_NULL},
|
||||
{ {HAWK_T("sub"), 3}, 0, { {2, 3, HAWK_T("xvr")}, hawk_fnc_sub, 0 }, HAWK_NULL},
|
||||
@ -131,7 +132,7 @@ static hawk_fnc_t* add_fnc (hawk_t* hawk, const hawk_ooch_t* name, const hawk_fn
|
||||
fnc->spec.arg.spec = tmp;
|
||||
}
|
||||
|
||||
if (hawk_htb_insert(hawk->fnc.user, (hawk_ooch_t*)ncs.ptr, ncs.len, fnc, 0) == HAWK_NULL)
|
||||
if (!hawk_htb_insert(hawk->fnc.user, (hawk_ooch_t*)ncs.ptr, ncs.len, fnc, 0))
|
||||
{
|
||||
const hawk_ooch_t* bem = hawk_backuperrmsg(hawk);
|
||||
hawk_seterrfmt (hawk, HAWK_NULL, hawk_geterrnum(hawk), HAWK_T("unable to add function - %js - %js"), name, bem);
|
||||
@ -349,12 +350,12 @@ static int fnc_close (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
HAWK_ASSERT (a0 != HAWK_NULL);
|
||||
|
||||
name = hawk_rtx_getvaloocstr(rtx, a0, &len);
|
||||
if (name == HAWK_NULL) return -1;
|
||||
if (!name) return -1;
|
||||
|
||||
if (a1)
|
||||
{
|
||||
opt = hawk_rtx_getvaloocstr(rtx, a1, &optlen);
|
||||
if (opt == HAWK_NULL)
|
||||
if (!opt)
|
||||
{
|
||||
hawk_rtx_freevaloocstr(rtx, a0, name);
|
||||
return -1;
|
||||
@ -410,7 +411,7 @@ skip_close:
|
||||
hawk_rtx_freevaloocstr (rtx, a0, name);
|
||||
|
||||
v = hawk_rtx_makeintval (rtx, (hawk_int_t)n);
|
||||
if (v == HAWK_NULL) return -1;
|
||||
if (!v) return -1;
|
||||
|
||||
hawk_rtx_setretval (rtx, v);
|
||||
return 0;
|
||||
@ -478,7 +479,7 @@ static int fnc_fflush (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
|
||||
a0 = hawk_rtx_getarg(rtx, 0);
|
||||
str0 = hawk_rtx_getvaloocstr(rtx, a0, &len0);
|
||||
if (str0 == HAWK_NULL) return -1;
|
||||
if (!str0) return -1;
|
||||
|
||||
/* the target name contains a null character.
|
||||
* make fflush return -1 */
|
||||
@ -533,7 +534,7 @@ static int fnc_fflush (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
}
|
||||
|
||||
v = hawk_rtx_makeintval (rtx, (hawk_int_t)n);
|
||||
if (v == HAWK_NULL) return -1;
|
||||
if (!v) return -1;
|
||||
|
||||
hawk_rtx_setretval (rtx, v);
|
||||
return 0;
|
||||
@ -605,7 +606,7 @@ static int index_or_rindex (hawk_rtx_t* rtx, int rindex)
|
||||
ptr = hawk_find_bchars_in_bchars(&str0[boundary-1], len0 - boundary + 1, str1, len1, rtx->gbl.ignorecase);
|
||||
}
|
||||
|
||||
idx = (ptr == HAWK_NULL)? 0: ((hawk_int_t)(ptr - str0) + 1);
|
||||
idx = (ptr? ((hawk_int_t)(ptr - str0) + 1): 0);
|
||||
|
||||
hawk_rtx_freevalbcstr (rtx, a1, str1);
|
||||
break;
|
||||
@ -651,7 +652,7 @@ static int index_or_rindex (hawk_rtx_t* rtx, int rindex)
|
||||
ptr = hawk_find_oochars_in_oochars(&str0[boundary-1], len0 - boundary + 1, str1, len1, rtx->gbl.ignorecase);
|
||||
}
|
||||
|
||||
idx = (ptr == HAWK_NULL)? 0: ((hawk_int_t)(ptr - str0) + 1);
|
||||
idx = (ptr? ((hawk_int_t)(ptr - str0) + 1): 0);
|
||||
|
||||
hawk_rtx_freevaloocstr (rtx, a1, str1);
|
||||
hawk_rtx_freevaloocstr (rtx, a0, str0);
|
||||
@ -957,13 +958,13 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
|
||||
hawk_rtx_tokoocharswithoochars(rtx, p, str.len, fs.ptr, fs.len, &tok);
|
||||
}
|
||||
|
||||
if (nflds == 0 && p == HAWK_NULL && tok.len == 0)
|
||||
if (nflds == 0 && !p && tok.len == 0)
|
||||
{
|
||||
/* no field at all*/
|
||||
break;
|
||||
}
|
||||
|
||||
HAWK_ASSERT ((tok.ptr != HAWK_NULL && tok.len > 0) || tok.len == 0);
|
||||
HAWK_ASSERT ((tok.ptr && tok.len > 0) || tok.len == 0);
|
||||
|
||||
/* create the field string - however, the split function must
|
||||
* create a numeric value if the string is a number */
|
||||
@ -975,7 +976,7 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
|
||||
|
||||
if (use_array)
|
||||
{
|
||||
if (hawk_rtx_setarrvalfld(rtx, t1, ++nflds, t2) == HAWK_NULL)
|
||||
if (!hawk_rtx_setarrvalfld(rtx, t1, ++nflds, t2))
|
||||
{
|
||||
hawk_rtx_refupval (rtx, t2);
|
||||
hawk_rtx_refdownval (rtx, t2);
|
||||
@ -991,7 +992,7 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
|
||||
key_len = hawk_int_to_oocstr(++nflds, 10, HAWK_NULL, key_buf, HAWK_COUNTOF(key_buf));
|
||||
HAWK_ASSERT (key_len != (hawk_oow_t)-1);
|
||||
|
||||
if (hawk_rtx_setmapvalfld(rtx, t1, key_buf, key_len, t2) == HAWK_NULL)
|
||||
if (!hawk_rtx_setmapvalfld(rtx, t1, key_buf, key_len, t2))
|
||||
{
|
||||
hawk_rtx_refupval (rtx, t2);
|
||||
hawk_rtx_refdownval (rtx, t2);
|
||||
@ -1616,23 +1617,8 @@ int hawk_fnc_sub (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
return __substitute(rtx, 1);
|
||||
}
|
||||
|
||||
int hawk_fnc_match (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
static int __fnc_match (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int support_start_index)
|
||||
{
|
||||
/*
|
||||
match("abcdefg", "cde");
|
||||
match("abcdefgdefx", "def", 7);
|
||||
------------------------------------
|
||||
match("ab\uB098cdefgdefx", /(def)g(.+)/, 1, x);
|
||||
q = length(x) / 2;
|
||||
for (i = 1; i <= q; i++) print x[i,"start"], x[i,"length"];
|
||||
print RSTART, RLENGTH;
|
||||
* ------------------------------------
|
||||
match(@b"ab\xB0\x98cdefgdefx", /(def)g(.+)/, 1, x);
|
||||
q = length(x) / 2;
|
||||
for (i = 1; i <= q; i++) print x[i,"start"], x[i,"length"];
|
||||
print RSTART, RLENGTH;
|
||||
*/
|
||||
|
||||
hawk_oow_t nargs;
|
||||
hawk_val_t* a0, * a1;
|
||||
hawk_val_type_t a0_type;
|
||||
@ -1666,15 +1652,11 @@ int hawk_fnc_match (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
a0 = hawk_rtx_getarg(rtx, 0);
|
||||
a1 = hawk_rtx_getarg(rtx, 1);
|
||||
|
||||
if (nargs >= 3)
|
||||
if (support_start_index && nargs >= 3)
|
||||
{
|
||||
hawk_val_t* a2;
|
||||
|
||||
a2 = hawk_rtx_getarg(rtx, 2);
|
||||
/* if the 3rd parameter is not an array,
|
||||
* it is treated as a match start index */
|
||||
n = hawk_rtx_valtoint(rtx, a2, &start);
|
||||
if (n <= -1) return -1;
|
||||
a2 = hawk_rtx_getarg(rtx, 2); /* when start index is support, this is the thrid argument */
|
||||
if (hawk_rtx_valtoint(rtx, a2, &start) <= -1) return -1;
|
||||
}
|
||||
|
||||
HAWK_MEMSET (&submat, 0, HAWK_SIZEOF(submat));
|
||||
@ -1694,7 +1676,7 @@ int hawk_fnc_match (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
tmp.ptr = str0.b + start - 1;
|
||||
tmp.len = len0 - start + 1;
|
||||
|
||||
n = hawk_rtx_matchvalwithbcs(rtx, a1, &tmp, &tmp, &mat.b, (nargs >= 4? submat.b: HAWK_NULL));
|
||||
n = hawk_rtx_matchvalwithbcs(rtx, a1, &tmp, &tmp, &mat.b, (nargs >= support_start_index + 3? submat.b: HAWK_NULL));
|
||||
hawk_rtx_freevalbcstr (rtx, a0, str0.b);
|
||||
|
||||
if (n <= -1) return -1;
|
||||
@ -1716,7 +1698,7 @@ int hawk_fnc_match (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
tmp.ptr = str0.o + start - 1;
|
||||
tmp.len = len0 - start + 1;
|
||||
|
||||
n = hawk_rtx_matchvalwithoocs(rtx, a1, &tmp, &tmp, &mat.o, (nargs >= 4? submat.o: HAWK_NULL));
|
||||
n = hawk_rtx_matchvalwithoocs(rtx, a1, &tmp, &tmp, &mat.o, (nargs >= support_start_index + 3? submat.o: HAWK_NULL));
|
||||
hawk_rtx_freevaloocstr (rtx, a0, str0.o);
|
||||
|
||||
if (n <= -1) return -1;
|
||||
@ -1731,11 +1713,12 @@ int hawk_fnc_match (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
|
||||
/* RLENGTH: -1 on no match */
|
||||
HAWK_ASSERT (&mat.o.len == &mat.b.len);
|
||||
//x1 = hawk_rtx_makeintval(rtx, ((n == 0)? (hawk_int_t)-1: (hawk_int_t)mat.o.len)); /* just use mat.o.len regardless of a0_type */
|
||||
x1 = hawk_rtx_makeintval(rtx, ((n == 0)? (hawk_int_t)-1: (hawk_int_t)mat.o.len)); /* just use mat.o.len regardless of a0_type */
|
||||
if (!x1) goto oops;
|
||||
hawk_rtx_refupval (rtx, x1);
|
||||
|
||||
if (nargs >= 4)
|
||||
if (nargs >= (3 + support_start_index))
|
||||
{
|
||||
const hawk_oocs_t* subsep;
|
||||
hawk_int_t submatcount;
|
||||
@ -1783,10 +1766,10 @@ int hawk_fnc_match (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
goto oops;
|
||||
}
|
||||
}
|
||||
|
||||
/* the caller of this function must be able to get the submatch count by
|
||||
* dividing the array size by 2 */
|
||||
|
||||
if (hawk_rtx_setrefval(rtx, (hawk_val_ref_t*)hawk_rtx_getarg(rtx, 3), x2) <= -1) goto oops;
|
||||
if (hawk_rtx_setrefval(rtx, (hawk_val_ref_t*)hawk_rtx_getarg(rtx, 2 + support_start_index), x2) <= -1) goto oops;
|
||||
}
|
||||
|
||||
if (hawk_rtx_setgbl(rtx, HAWK_GBL_RSTART, x0) <= -1 ||
|
||||
@ -1809,6 +1792,44 @@ oops:
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int fnc_match (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
{
|
||||
/*
|
||||
match("abcdefg", "cde");
|
||||
match("abcdefgdefx", "def", 7);
|
||||
------------------------------------
|
||||
match("ab\uB098cdefgdefx", /(def)g(.+)/, x);
|
||||
q = length(x) / 2;
|
||||
for (i = 1; i <= q; i++) print x[i,"start"], x[i,"length"];
|
||||
print RSTART, RLENGTH;
|
||||
* ------------------------------------
|
||||
match(@b"ab\xB0\x98cdefgdefx", /(def)g(.+)/, x);
|
||||
q = length(x) / 2;
|
||||
for (i = 1; i <= q; i++) print x[i,"start"], x[i,"length"];
|
||||
print RSTART, RLENGTH;
|
||||
*/
|
||||
return __fnc_match(rtx, fi, 0);
|
||||
}
|
||||
|
||||
int hawk_fnc_match (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
{
|
||||
/*
|
||||
str::match("abcdefg", "cde");
|
||||
str::match("abcdefgdefx", "def", 7);
|
||||
------------------------------------
|
||||
str::match("ab\uB098cdefgdefx", /(def)g(.+)/, 1, x);
|
||||
q = length(x) / 2;
|
||||
for (i = 1; i <= q; i++) print x[i,"start"], x[i,"length"];
|
||||
print RSTART, RLENGTH;
|
||||
* ------------------------------------
|
||||
str::match(@b"ab\xB0\x98cdefgdefx", /(def)g(.+)/, 1, x);
|
||||
q = length(x) / 2;
|
||||
for (i = 1; i <= q; i++) print x[i,"start"], x[i,"length"];
|
||||
print RSTART, RLENGTH;
|
||||
*/
|
||||
return __fnc_match(rtx, fi, 1);
|
||||
}
|
||||
|
||||
int hawk_fnc_sprintf (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
{
|
||||
hawk_oow_t nargs;
|
||||
@ -1894,7 +1915,7 @@ static int fnc_int (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
|
||||
if (n <= -1) return -1;
|
||||
|
||||
r = hawk_rtx_makeintval(rtx, lv);
|
||||
if (r == HAWK_NULL) return -1;
|
||||
if (!r) return -1;
|
||||
|
||||
hawk_rtx_setretval (rtx, r);
|
||||
return 0;
|
||||
@ -2080,7 +2101,7 @@ val_map:
|
||||
HAWK_NULL
|
||||
);
|
||||
|
||||
if (hawk_rtx_setmapvalfld(rtx, rrv, ridx, ridx_len, va[i]) == HAWK_NULL)
|
||||
if (!hawk_rtx_setmapvalfld(rtx, rrv, ridx, ridx_len, va[i]))
|
||||
{
|
||||
/* decrement the reference count of the values not added to the map */
|
||||
do
|
||||
@ -2153,7 +2174,7 @@ val_arr:
|
||||
|
||||
for (i = 0; i < msz; i++)
|
||||
{
|
||||
if (hawk_rtx_setarrvalfld(rtx, rrv, i + 1, va[i]) == HAWK_NULL) /* i + 1 for 1-based indexing*/
|
||||
if (!hawk_rtx_setarrvalfld(rtx, rrv, i + 1, va[i])) /* i + 1 for 1-based indexing*/
|
||||
{
|
||||
/* decrement the reference count of the values not added to the map */
|
||||
do
|
||||
|
@ -2407,7 +2407,6 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_execwithbcstrarr (
|
||||
# define hawk_rtx_execwithoocstrarr hawk_rtx_execwithucstrarr
|
||||
|
||||
# define hawk_rtx_call hawk_rtx_callwithucstr
|
||||
# define hawk_rtx_call hawk_rtx_callwithucstrarr
|
||||
# define hawk_rtx_exec hawk_rtx_execwithucstrarr
|
||||
#else
|
||||
# define hawk_rtx_callwithoocstr hawk_rtx_callwithbcstr
|
||||
@ -2415,7 +2414,6 @@ HAWK_EXPORT hawk_val_t* hawk_rtx_execwithbcstrarr (
|
||||
# define hawk_rtx_execwithoocstrarr hawk_rtx_execwithbcstrarr
|
||||
|
||||
# define hawk_rtx_call hawk_rtx_callwithbcstr
|
||||
# define hawk_rtx_call hawk_rtx_callwithbcstrarr
|
||||
# define hawk_rtx_exec hawk_rtx_execwithbcstrarr
|
||||
#endif
|
||||
|
||||
|
59
t/h-002.hawk
59
t/h-002.hawk
@ -579,6 +579,65 @@ function main()
|
||||
tap_ensure (c === @b'y' , 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
@local a, b;
|
||||
|
||||
RSTART=99;
|
||||
RLENGTH=99;
|
||||
tap_ensure (match("world", /hello/), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RSTART, 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RLENGTH, -1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
tap_ensure (match(@b"world", /hello/), 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RSTART, 0, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RLENGTH, -1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
## match() doesn't support the start index.
|
||||
## the result goes to the third argument.
|
||||
tap_ensure (match("hello, world", /l/), 3, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RSTART, 3, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RLENGTH, 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
tap_ensure (match(@b"hello, world", /l/), 3, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RSTART, 3, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RLENGTH, 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
tap_ensure (match("hello, world", /(l)lo.*(l)/, a), 3, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RSTART, 3, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RLENGTH, 9, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (length(a), 4, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (a[1,"start"], 3, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (a[1,"length"], 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (a[2,"start"], 11, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (a[2,"length"], 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
## start::match() support the start index via the third parameter.
|
||||
## the result goes to the fourth argument.
|
||||
tap_ensure (str::match("hello, world", /(l)lo.*(l)/, 1, a), 3, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RSTART, 3, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RLENGTH, 9, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (length(a), 4, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (a[1,"start"], 3, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (a[1,"length"], 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (a[2,"start"], 11, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (a[2,"length"], 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
tap_ensure (str::match("hello, world, hello, world", /(l)lo.*(l)/, 4, a), 17, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RSTART, 17, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RLENGTH, 9, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (length(a), 4, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (a[1,"start"], 17, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (a[1,"length"], 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (a[2,"start"], 25, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (a[2,"length"], 1, @SCRIPTNAME, @SCRIPTLINE);
|
||||
|
||||
|
||||
b = 291210;
|
||||
tap_ensure (str::match(b @b"what is this", /10/, 1, a), 5, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RSTART, 5, @SCRIPTNAME, @SCRIPTLINE);
|
||||
tap_ensure (RLENGTH, 2, @SCRIPTNAME, @SCRIPTLINE);
|
||||
}
|
||||
tap_end ();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user