some code fixes and refactoring
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-08-31 11:36:25 +09:00
parent 8e1ef21150
commit 8f1b8ffc03
14 changed files with 216 additions and 226 deletions

View File

@ -860,7 +860,8 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
hawk_oocs_t tok;
hawk_int_t nflds;
int x, byte_str, do_fld = 0;
int is_byte_str;
int x, do_fld = 0;
int switch_fs_to_bchr = 0;
str.ptr = HAWK_NULL;
@ -874,6 +875,7 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
str.ptr = HAWK_NULL;
str.len = 0;
is_byte_str = 0;
/* field seperator */
t0 = a2? a2: hawk_rtx_getgbl(rtx, HAWK_GBL_FS); /* if a2 is not available, get the value from FS */
@ -934,13 +936,13 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
case HAWK_VAL_BCHR:
case HAWK_VAL_MBS:
case HAWK_VAL_BOB:
byte_str = 1;
is_byte_str = 1;
str.ptr = do_fld? (hawk_ooch_t*)hawk_rtx_valtobcstrdup(rtx, a0, &str.len):
(hawk_ooch_t*)hawk_rtx_getvalbcstr(rtx, a0, &str.len);
break;
default:
byte_str = 0;
is_byte_str = 0;
str.ptr = do_fld? hawk_rtx_valtooocstrdup(rtx, a0, &str.len):
hawk_rtx_getvaloocstr(rtx, a0, &str.len);
break;
@ -948,7 +950,7 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
if (HAWK_UNLIKELY(!str.ptr)) goto oops;
if (byte_str && switch_fs_to_bchr)
if (is_byte_str && switch_fs_to_bchr)
{
HAWK_ASSERT (fs_free = fs.ptr);
@ -975,20 +977,20 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
{
if (fs_rex)
{
p = byte_str? (hawk_ooch_t*)hawk_rtx_tokbcharsbyrex(rtx, (hawk_bch_t*)str.ptr, org_len, (hawk_bch_t*)p, str.len, fs_rex, (hawk_bcs_t*)&tok):
p = is_byte_str? (hawk_ooch_t*)hawk_rtx_tokbcharsbyrex(rtx, (hawk_bch_t*)str.ptr, org_len, (hawk_bch_t*)p, str.len, fs_rex, (hawk_bcs_t*)&tok):
hawk_rtx_tokoocharsbyrex(rtx, str.ptr, org_len, p, str.len, fs_rex, &tok);
if (p && hawk_rtx_geterrnum(rtx) != HAWK_ENOERR) goto oops;
}
else if (do_fld)
{
/* [NOTE] even if byte_str is true, the field seperator is of the ooch type.
/* [NOTE] even if is_byte_str is true, the field seperator is of the ooch type.
* there may be some data truncation and related issues */
p = byte_str? (hawk_ooch_t*)hawk_rtx_fldbchars(rtx, (hawk_bch_t*)p, str.len, fs.ptr[1], fs.ptr[2], fs.ptr[3], fs.ptr[4], (hawk_bcs_t*)&tok):
p = is_byte_str? (hawk_ooch_t*)hawk_rtx_fldbchars(rtx, (hawk_bch_t*)p, str.len, fs.ptr[1], fs.ptr[2], fs.ptr[3], fs.ptr[4], (hawk_bcs_t*)&tok):
hawk_rtx_fldoochars(rtx, p, str.len, fs.ptr[1], fs.ptr[2], fs.ptr[3], fs.ptr[4], &tok);
}
else
{
p = byte_str? (hawk_ooch_t*)hawk_rtx_tokbcharswithbchars(rtx, (hawk_bch_t*)p, str.len, (hawk_bch_t*)fs.ptr, fs.len, (hawk_bcs_t*)&tok):
p = is_byte_str? (hawk_ooch_t*)hawk_rtx_tokbcharswithbchars(rtx, (hawk_bch_t*)p, str.len, (hawk_bch_t*)fs.ptr, fs.len, (hawk_bcs_t*)&tok):
hawk_rtx_tokoocharswithoochars(rtx, p, str.len, fs.ptr, fs.len, &tok);
}
@ -1004,7 +1006,7 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
* create a numeric value if the string is a number */
/*t2 = hawk_rtx_makestrvalwithoocs(rtx, &tok);*/
/*t2 = hawk_rtx_makenstrvalwithoocs(rtx, &tok); */
t2 = byte_str? hawk_rtx_makenumormbsvalwithbchars(rtx, (hawk_bch_t*)tok.ptr, tok.len):
t2 = is_byte_str? hawk_rtx_makenumormbsvalwithbchars(rtx, (hawk_bch_t*)tok.ptr, tok.len):
hawk_rtx_makenumorstrvalwithoochars(rtx, tok.ptr, tok.len);
if (HAWK_UNLIKELY(!t2)) goto oops;
@ -1034,19 +1036,19 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
}
}
if (byte_str)
if (is_byte_str)
str.len = org_len - ((hawk_bch_t*)p - (hawk_bch_t*)str.ptr);
else
str.len = org_len - (p - str.ptr);
}
if (do_fld) { hawk_rtx_freemem(rtx, str.ptr); }
else if (byte_str) { hawk_rtx_freevalbcstr(rtx, a0, (hawk_bch_t*)str.ptr); }
else if (is_byte_str) { hawk_rtx_freevalbcstr(rtx, a0, (hawk_bch_t*)str.ptr); }
else { hawk_rtx_freevaloocstr(rtx, a0, str.ptr); }
if (fs_free)
{
if (byte_str && switch_fs_to_bchr)
if (is_byte_str && switch_fs_to_bchr)
hawk_rtx_freevalbcstr(rtx, t0, (hawk_bch_t*)fs_free);
else
hawk_rtx_freevaloocstr(rtx, t0, fs_free);
@ -1070,13 +1072,13 @@ oops:
if (str.ptr)
{
if (do_fld) { hawk_rtx_freemem(rtx, str.ptr); }
else if (byte_str) { hawk_rtx_freevalbcstr(rtx, a0, (hawk_bch_t*)str.ptr); }
else if (is_byte_str) { hawk_rtx_freevalbcstr(rtx, a0, (hawk_bch_t*)str.ptr); }
else { hawk_rtx_freevaloocstr(rtx, a0, str.ptr); }
}
if (fs_free)
{
if (byte_str && switch_fs_to_bchr)
if (is_byte_str && switch_fs_to_bchr)
hawk_rtx_freevalbcstr(rtx, t0, (hawk_bch_t*)fs_free);
else
hawk_rtx_freevaloocstr(rtx, t0, fs_free);
@ -1473,6 +1475,9 @@ static int __substitute (hawk_rtx_t* rtx, hawk_oow_t max_count)
s1.ptr = HAWK_NULL;
s1.len = 0;
s2.ptr = HAWK_NULL;
s2.len = 0;
nargs = hawk_rtx_getnargs(rtx);
a0 = hawk_rtx_getarg(rtx, 0);
a1 = hawk_rtx_getarg(rtx, 1);
@ -1702,6 +1707,9 @@ int hawk_fnc_gensub (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
s1.ptr = HAWK_NULL;
s1.len = 0;
s2.ptr = HAWK_NULL;
s2.len = 0;
nargs = hawk_rtx_getnargs(rtx);
a0 = hawk_rtx_getarg(rtx, 0); /* pattern */
a1 = hawk_rtx_getarg(rtx, 1); /* substitute */