From daf737740397fb90e290f07c8a7b32b74d281338 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Fri, 13 Nov 2020 15:09:29 +0000 Subject: [PATCH] added str::splita() --- hawk/lib/fnc-prv.h | 1 + hawk/lib/fnc.c | 6 +++++- hawk/lib/mod-str.c | 1 + hawk/t/h-002.hawk | 5 ++++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/hawk/lib/fnc-prv.h b/hawk/lib/fnc-prv.h index 5ff19777..1d036377 100644 --- a/hawk/lib/fnc-prv.h +++ b/hawk/lib/fnc-prv.h @@ -64,6 +64,7 @@ HAWK_EXPORT int hawk_fnc_length (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi); HAWK_EXPORT int hawk_fnc_match (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi); HAWK_EXPORT int hawk_fnc_rindex (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi); HAWK_EXPORT int hawk_fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi); +HAWK_EXPORT int hawk_fnc_splita (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi); HAWK_EXPORT int hawk_fnc_sprintf (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi); HAWK_EXPORT int hawk_fnc_sub (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi); HAWK_EXPORT int hawk_fnc_substr (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi); diff --git a/hawk/lib/fnc.c b/hawk/lib/fnc.c index 06b7c41f..a17a0c8f 100644 --- a/hawk/lib/fnc.c +++ b/hawk/lib/fnc.c @@ -1001,10 +1001,14 @@ oops: int hawk_fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) { - /*return fnc_split(rtx, fi, 1);*/ return fnc_split(rtx, fi, 0); } +int hawk_fnc_splita (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) +{ + return fnc_split(rtx, fi, 1); +} + int hawk_fnc_tolower (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi) { hawk_oow_t i; diff --git a/hawk/lib/mod-str.c b/hawk/lib/mod-str.c index 5cb130fd..0496a98f 100644 --- a/hawk/lib/mod-str.c +++ b/hawk/lib/mod-str.c @@ -574,6 +574,7 @@ static fnctab_t fnctab[] = { HAWK_T("rindex"), { { 2, 3, HAWK_NULL }, hawk_fnc_rindex, 0 } }, { HAWK_T("rtrim"), { { 1, 1, HAWK_NULL }, fnc_rtrim, 0 } }, { HAWK_T("split"), { { 2, 3, HAWK_T("vrx") }, hawk_fnc_split, 0 } }, + { HAWK_T("splita"), { { 2, 3, HAWK_T("vrx") }, hawk_fnc_splita, 0 } }, /* split to array. asplit is not a good name for this */ { HAWK_T("sub"), { { 2, 3, HAWK_T("xvr") }, hawk_fnc_sub, 0 } }, { HAWK_T("substr"), { { 2, 3, HAWK_NULL }, hawk_fnc_substr, 0 } }, { HAWK_T("tocharcode"), { { 1, 2, HAWK_NULL }, fnc_tocharcode, 0 } }, diff --git a/hawk/t/h-002.hawk b/hawk/t/h-002.hawk index 4760dcdd..3f7a61ef 100644 --- a/hawk/t/h-002.hawk +++ b/hawk/t/h-002.hawk @@ -310,7 +310,10 @@ function main() ensure (a[3] === @b"So]me", 1, @SCRIPTNAME, @SCRIPTLINE); ensure (a[4] === @b"Da:ta", 1, @SCRIPTNAME, @SCRIPTLINE); - ensure (split("Here===Is=Some=====Data", a, ""), 23, @SCRIPTNAME, @SCRIPTLINE); + ensure (split("Here===Is=Some=====Data", a, ""), 23, @SCRIPTNAME, @SCRIPTLINE); + ensure (hawk::typename(a), "map", @SCRIPTNAME, @SCRIPTLINE); + ensure (str::splita("Here===Is=Some=====Data", a, ""), 23, @SCRIPTNAME, @SCRIPTLINE); + ensure (hawk::typename(a), "array",@SCRIPTNAME, @SCRIPTLINE); ensure (split("Here Is Some Data", a, / /), 7, @SCRIPTNAME, @SCRIPTLINE); ensure (split("Here Is Some Data", a, " "), 4, @SCRIPTNAME, @SCRIPTLINE);