exposed str::match(), str::printf(), str::sub(), str::gsub()
This commit is contained in:
parent
b75630a8bb
commit
9ec0981157
@ -23,10 +23,6 @@
|
|||||||
static int fnc_close (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
static int fnc_close (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
||||||
static int fnc_fflush (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
static int fnc_fflush (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
||||||
static int fnc_index (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
static int fnc_index (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
||||||
static int fnc_gsub (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
|
||||||
static int fnc_sub (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
|
||||||
static int fnc_match (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
|
||||||
static int fnc_sprintf (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
|
||||||
|
|
||||||
static int fnc_sin (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
static int fnc_sin (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
||||||
static int fnc_cos (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
static int fnc_cos (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
||||||
@ -67,10 +63,10 @@ static qse_awk_fnc_t sysfnctab[] =
|
|||||||
{ {QSE_T("split"), 5}, 0, { {2, 3, QSE_T("vrx")}, qse_awk_fnc_split, 0 }, QSE_NULL},
|
{ {QSE_T("split"), 5}, 0, { {2, 3, QSE_T("vrx")}, qse_awk_fnc_split, 0 }, QSE_NULL},
|
||||||
{ {QSE_T("tolower"), 7}, 0, { {1, 1, QSE_NULL}, qse_awk_fnc_tolower, 0 }, QSE_NULL},
|
{ {QSE_T("tolower"), 7}, 0, { {1, 1, QSE_NULL}, qse_awk_fnc_tolower, 0 }, QSE_NULL},
|
||||||
{ {QSE_T("toupper"), 7}, 0, { {1, 1, QSE_NULL}, qse_awk_fnc_toupper, 0 }, QSE_NULL},
|
{ {QSE_T("toupper"), 7}, 0, { {1, 1, QSE_NULL}, qse_awk_fnc_toupper, 0 }, QSE_NULL},
|
||||||
{ {QSE_T("gsub"), 4}, 0, { {2, 3, QSE_T("xvr")}, fnc_gsub, 0 }, QSE_NULL},
|
{ {QSE_T("gsub"), 4}, 0, { {2, 3, QSE_T("xvr")}, qse_awk_fnc_gsub, 0 }, QSE_NULL},
|
||||||
{ {QSE_T("sub"), 3}, 0, { {2, 3, QSE_T("xvr")}, fnc_sub, 0 }, QSE_NULL},
|
{ {QSE_T("sub"), 3}, 0, { {2, 3, QSE_T("xvr")}, qse_awk_fnc_sub, 0 }, QSE_NULL},
|
||||||
{ {QSE_T("match"), 5}, 0, { {2, 3, QSE_T("vxv")}, fnc_match, 0 }, QSE_NULL},
|
{ {QSE_T("match"), 5}, 0, { {2, 3, QSE_T("vxv")}, qse_awk_fnc_match, 0 }, QSE_NULL},
|
||||||
{ {QSE_T("sprintf"), 7}, 0, { {1, A_MAX, QSE_NULL}, fnc_sprintf, 0 }, QSE_NULL},
|
{ {QSE_T("sprintf"), 7}, 0, { {1, A_MAX, QSE_NULL}, qse_awk_fnc_sprintf, 0 }, QSE_NULL},
|
||||||
|
|
||||||
/* math functions */
|
/* math functions */
|
||||||
{ {QSE_T("sin"), 3}, 0, { {1, 1, QSE_NULL}, fnc_sin, 0 }, QSE_NULL},
|
{ {QSE_T("sin"), 3}, 0, { {1, 1, QSE_NULL}, fnc_sin, 0 }, QSE_NULL},
|
||||||
@ -1086,17 +1082,17 @@ oops:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fnc_gsub (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi)
|
int qse_awk_fnc_gsub (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi)
|
||||||
{
|
{
|
||||||
return __substitute (run, 0);
|
return __substitute (run, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fnc_sub (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi)
|
int qse_awk_fnc_sub (qse_awk_rtx_t* run, const qse_awk_fnc_info_t* fi)
|
||||||
{
|
{
|
||||||
return __substitute (run, 1);
|
return __substitute (run, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fnc_match (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
int qse_awk_fnc_match (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||||
{
|
{
|
||||||
qse_size_t nargs;
|
qse_size_t nargs;
|
||||||
qse_awk_val_t* a0, * a1;
|
qse_awk_val_t* a0, * a1;
|
||||||
@ -1196,7 +1192,7 @@ static int fnc_match (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fnc_sprintf (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
int qse_awk_fnc_sprintf (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
|
||||||
{
|
{
|
||||||
qse_size_t nargs;
|
qse_size_t nargs;
|
||||||
qse_awk_val_t* a0;
|
qse_awk_val_t* a0;
|
||||||
|
@ -45,8 +45,12 @@ qse_awk_fnc_t* qse_awk_findfnc (qse_awk_t* awk, const qse_cstr_t* name);
|
|||||||
int qse_awk_fnc_length (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
int qse_awk_fnc_length (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
||||||
int qse_awk_fnc_substr (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
int qse_awk_fnc_substr (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
||||||
int qse_awk_fnc_split (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
int qse_awk_fnc_split (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
||||||
|
int qse_awk_fnc_match (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
||||||
|
int qse_awk_fnc_gsub (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
||||||
|
int qse_awk_fnc_sub (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
||||||
int qse_awk_fnc_tolower (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
int qse_awk_fnc_tolower (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
||||||
int qse_awk_fnc_toupper (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
int qse_awk_fnc_toupper (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
||||||
|
int qse_awk_fnc_sprintf (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -294,9 +294,15 @@ struct fnctab_t
|
|||||||
qse_awk_mod_sym_fnc_t info;
|
qse_awk_mod_sym_fnc_t info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* TODO: match. let str::match() change str::RLENGTH and str::RSTART */
|
||||||
|
/* TODO: index. reuse fnc_index() in fnc.c */
|
||||||
|
|
||||||
|
#define A_MAX QSE_TYPE_MAX(int)
|
||||||
|
|
||||||
static fnctab_t fnctab[] =
|
static fnctab_t fnctab[] =
|
||||||
{
|
{
|
||||||
/* keep this table sorted for binary search in query(). */
|
/* keep this table sorted for binary search in query(). */
|
||||||
|
{ QSE_T("gsub"), { { 2, 3, QSE_T("xvr")}, qse_awk_fnc_gsub, 0 } },
|
||||||
{ QSE_T("index"), { { 2, 3, QSE_NULL }, fnc_index, 0 } },
|
{ QSE_T("index"), { { 2, 3, QSE_NULL }, fnc_index, 0 } },
|
||||||
{ QSE_T("isalnum"), { { 1, 1, QSE_NULL }, fnc_isalnum, 0 } },
|
{ QSE_T("isalnum"), { { 1, 1, QSE_NULL }, fnc_isalnum, 0 } },
|
||||||
{ QSE_T("isalpha"), { { 1, 1, QSE_NULL }, fnc_isalpha, 0 } },
|
{ QSE_T("isalpha"), { { 1, 1, QSE_NULL }, fnc_isalpha, 0 } },
|
||||||
@ -312,10 +318,13 @@ static fnctab_t fnctab[] =
|
|||||||
{ QSE_T("isxdigit"), { { 1, 1, QSE_NULL }, fnc_isxdigit, 0 } },
|
{ QSE_T("isxdigit"), { { 1, 1, QSE_NULL }, fnc_isxdigit, 0 } },
|
||||||
{ QSE_T("length"), { { 1, 1, QSE_NULL }, qse_awk_fnc_length, 0 } },
|
{ QSE_T("length"), { { 1, 1, QSE_NULL }, qse_awk_fnc_length, 0 } },
|
||||||
{ QSE_T("ltrim"), { { 1, 1, QSE_NULL }, fnc_ltrim, 0 } },
|
{ QSE_T("ltrim"), { { 1, 1, QSE_NULL }, fnc_ltrim, 0 } },
|
||||||
|
{ QSE_T("match"), { { 2, 3, QSE_T("vxv") }, qse_awk_fnc_match, 0 } },
|
||||||
{ QSE_T("normspace"), { { 1, 1, QSE_NULL }, fnc_normspace, 0 } },
|
{ QSE_T("normspace"), { { 1, 1, QSE_NULL }, fnc_normspace, 0 } },
|
||||||
|
{ QSE_T("printf"), { { 1, A_MAX, QSE_NULL }, qse_awk_fnc_sprintf, 0 } },
|
||||||
{ QSE_T("rindex"), { { 2, 3, QSE_NULL }, fnc_rindex, 0 } },
|
{ QSE_T("rindex"), { { 2, 3, QSE_NULL }, fnc_rindex, 0 } },
|
||||||
{ QSE_T("rtrim"), { { 1, 1, QSE_NULL }, fnc_rtrim, 0 } },
|
{ QSE_T("rtrim"), { { 1, 1, QSE_NULL }, fnc_rtrim, 0 } },
|
||||||
{ QSE_T("split"), { { 2, 3, QSE_T("vrx") }, qse_awk_fnc_split, 0 } },
|
{ QSE_T("split"), { { 2, 3, QSE_T("vrx") }, qse_awk_fnc_split, 0 } },
|
||||||
|
{ QSE_T("sub"), { { 2, 3, QSE_T("xvr") }, qse_awk_fnc_sub, 0 } },
|
||||||
{ QSE_T("substr"), { { 2, 3, QSE_NULL }, qse_awk_fnc_substr, 0 } },
|
{ QSE_T("substr"), { { 2, 3, QSE_NULL }, qse_awk_fnc_substr, 0 } },
|
||||||
{ QSE_T("tolower"), { { 1, 1, QSE_NULL }, qse_awk_fnc_tolower, 0 } },
|
{ QSE_T("tolower"), { { 1, 1, QSE_NULL }, qse_awk_fnc_tolower, 0 } },
|
||||||
{ QSE_T("toupper"), { { 1, 1, QSE_NULL }, qse_awk_fnc_toupper, 0 } },
|
{ QSE_T("toupper"), { { 1, 1, QSE_NULL }, qse_awk_fnc_toupper, 0 } },
|
||||||
|
Loading…
Reference in New Issue
Block a user