adding some primitive functions
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
14
mod/str.c
14
mod/str.c
@ -122,9 +122,9 @@ static hcl_pfrc_t pf_str_length (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs)
|
||||
return HCL_PF_SUCCESS;
|
||||
}
|
||||
|
||||
static hcl_pfrc_t pf_str_substr (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs)
|
||||
static hcl_pfrc_t pf_str_slice (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs)
|
||||
{
|
||||
hcl_oop_t str, substr, a1, a2;
|
||||
hcl_oop_t str, slice, a1, a2;
|
||||
hcl_ooi_t size;
|
||||
hcl_ooi_t pos;
|
||||
hcl_ooi_t len;
|
||||
@ -156,10 +156,10 @@ static hcl_pfrc_t pf_str_substr (hcl_t* hcl, hcl_mod_t* mod, hcl_ooi_t nargs)
|
||||
if (pos < 0) pos = 0;
|
||||
else if (pos >= size) pos = size;
|
||||
if (len >= size - pos) len = size - pos;
|
||||
substr = hcl_makestring(hcl, HCL_OBJ_GET_CHAR_PTR(str, pos), len, 0);
|
||||
if (HCL_UNLIKELY(!substr)) return HCL_PF_FAILURE;
|
||||
slice = hcl_makestring(hcl, HCL_OBJ_GET_CHAR_PTR(str, pos), len, 0);
|
||||
if (HCL_UNLIKELY(!slice)) return HCL_PF_FAILURE;
|
||||
|
||||
HCL_STACK_SETRET (hcl, nargs, substr);
|
||||
HCL_STACK_SETRET (hcl, nargs, slice);
|
||||
return HCL_PF_SUCCESS;
|
||||
}
|
||||
|
||||
@ -169,7 +169,9 @@ static hcl_pfinfo_t pfinfos[] =
|
||||
{ { 'a','t','\0' }, { HCL_PFBASE_FUNC, pf_str_at, 2, 2 } },
|
||||
{ { 'a','t','P','u','t','\0' }, { HCL_PFBASE_FUNC, pf_str_at_put, 3, 3 } },
|
||||
{ { 'l','e','n','g','t','h','\0' }, { HCL_PFBASE_FUNC, pf_str_length, 1, 1 } },
|
||||
{ { 's','u','b','s','t','r'}, { HCL_PFBASE_FUNC, pf_str_substr, 3, 3 } }
|
||||
{ { 's','i','z','e'}, { HCL_PFBASE_FUNC, pf_str_length, 1, 1 } },
|
||||
{ { 's','l','i','c','e'}, { HCL_PFBASE_FUNC, pf_str_slice, 3, 3 } },
|
||||
{ { 's','u','b','s','t','r'}, { HCL_PFBASE_FUNC, pf_str_slice, 3, 3 } }
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
Reference in New Issue
Block a user