fixed bugs in sys::split()
This commit is contained in:
parent
2eb3c1a5c1
commit
9ea3344469
@ -827,6 +827,7 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
|
|||||||
hawk_oocs_t tok;
|
hawk_oocs_t tok;
|
||||||
hawk_int_t nflds;
|
hawk_int_t nflds;
|
||||||
int x, byte_str, do_fld = 0;
|
int x, byte_str, do_fld = 0;
|
||||||
|
int switch_fs_to_bchr = 0;
|
||||||
|
|
||||||
str.ptr = HAWK_NULL;
|
str.ptr = HAWK_NULL;
|
||||||
str.len = 0;
|
str.len = 0;
|
||||||
@ -887,6 +888,10 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
|
|||||||
fs_rex = rtx->gbl.fs[rtx->gbl.ignorecase];
|
fs_rex = rtx->gbl.fs[rtx->gbl.ignorecase];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch_fs_to_bchr = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the first parameter - string to split */
|
/* the first parameter - string to split */
|
||||||
@ -895,8 +900,8 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
|
|||||||
case HAWK_VAL_BCHR:
|
case HAWK_VAL_BCHR:
|
||||||
case HAWK_VAL_MBS:
|
case HAWK_VAL_MBS:
|
||||||
byte_str = 1;
|
byte_str = 1;
|
||||||
str.ptr = do_fld? hawk_rtx_valtobcstrdup(rtx, a0, &str.len):
|
str.ptr = do_fld? (hawk_ooch_t*)hawk_rtx_valtobcstrdup(rtx, a0, &str.len):
|
||||||
hawk_rtx_getvalbcstr(rtx, a0, &str.len);
|
(hawk_ooch_t*)hawk_rtx_getvalbcstr(rtx, a0, &str.len);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -907,6 +912,19 @@ 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 (HAWK_UNLIKELY(!str.ptr)) goto oops;
|
||||||
|
|
||||||
|
|
||||||
|
if (byte_str && switch_fs_to_bchr)
|
||||||
|
{
|
||||||
|
HAWK_ASSERT (fs_free = fs.ptr);
|
||||||
|
|
||||||
|
hawk_rtx_freevaloocstr (rtx, t0, fs_free);
|
||||||
|
|
||||||
|
fs.ptr = (hawk_ooch_t*)hawk_rtx_getvalbcstr(rtx, t0, &fs.len);
|
||||||
|
if (HAWK_UNLIKELY(!fs.ptr)) goto oops;
|
||||||
|
|
||||||
|
fs_free = fs.ptr;
|
||||||
|
}
|
||||||
|
|
||||||
t1 = use_array? hawk_rtx_makearrval(rtx, 16): hawk_rtx_makemapval(rtx);
|
t1 = use_array? hawk_rtx_makearrval(rtx, 16): hawk_rtx_makemapval(rtx);
|
||||||
if (HAWK_UNLIKELY(!t1)) goto oops;
|
if (HAWK_UNLIKELY(!t1)) goto oops;
|
||||||
|
|
||||||
@ -922,7 +940,7 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
|
|||||||
{
|
{
|
||||||
if (fs_rex)
|
if (fs_rex)
|
||||||
{
|
{
|
||||||
p = byte_str? hawk_rtx_tokbcharsbyrex(rtx, str.ptr, org_len, p, str.len, fs_rex, &tok):
|
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):
|
||||||
hawk_rtx_tokoocharsbyrex(rtx, str.ptr, org_len, p, str.len, fs_rex, &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;
|
if (p && hawk_rtx_geterrnum(rtx) != HAWK_ENOERR) goto oops;
|
||||||
}
|
}
|
||||||
@ -930,12 +948,12 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
|
|||||||
{
|
{
|
||||||
/* [NOTE] even if byte_str is true, the field seperator is of the ooch type.
|
/* [NOTE] even if byte_str is true, the field seperator is of the ooch type.
|
||||||
* there may be some data truncation and related issues */
|
* there may be some data truncation and related issues */
|
||||||
p = byte_str? hawk_rtx_fldbchars(rtx, p, str.len, fs.ptr[1], fs.ptr[2], fs.ptr[3], fs.ptr[4], &tok):
|
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):
|
||||||
hawk_rtx_fldoochars(rtx, p, str.len, fs.ptr[1], fs.ptr[2], fs.ptr[3], fs.ptr[4], &tok);
|
hawk_rtx_fldoochars(rtx, p, str.len, fs.ptr[1], fs.ptr[2], fs.ptr[3], fs.ptr[4], &tok);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
p = byte_str? hawk_rtx_tokbcharswithbchars(rtx, p, str.len, fs.ptr, fs.len, &tok):
|
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):
|
||||||
hawk_rtx_tokoocharswithoochars(rtx, p, str.len, fs.ptr, fs.len, &tok);
|
hawk_rtx_tokoocharswithoochars(rtx, p, str.len, fs.ptr, fs.len, &tok);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -951,7 +969,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 */
|
* create a numeric value if the string is a number */
|
||||||
/*t2 = hawk_rtx_makestrvalwithoocs (rtx, &tok);*/
|
/*t2 = hawk_rtx_makestrvalwithoocs (rtx, &tok);*/
|
||||||
/*t2 = hawk_rtx_makenstrvalwithoocs(rtx, &tok); */
|
/*t2 = hawk_rtx_makenstrvalwithoocs(rtx, &tok); */
|
||||||
t2 = byte_str? hawk_rtx_makenumormbsvalwithbchars(rtx, tok.ptr, tok.len):
|
t2 = byte_str? hawk_rtx_makenumormbsvalwithbchars(rtx, (hawk_bch_t*)tok.ptr, tok.len):
|
||||||
hawk_rtx_makenumorstrvalwithoochars(rtx, tok.ptr, tok.len);
|
hawk_rtx_makenumorstrvalwithoochars(rtx, tok.ptr, tok.len);
|
||||||
if (HAWK_UNLIKELY(!t2)) goto oops;
|
if (HAWK_UNLIKELY(!t2)) goto oops;
|
||||||
|
|
||||||
@ -988,10 +1006,16 @@ static int fnc_split (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi, int use_array)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (do_fld) { hawk_rtx_freemem (rtx, str.ptr); }
|
if (do_fld) { hawk_rtx_freemem (rtx, str.ptr); }
|
||||||
else if (byte_str) { hawk_rtx_freevalbcstr (rtx, a0, str.ptr); }
|
else if (byte_str) { hawk_rtx_freevalbcstr (rtx, a0, (hawk_bch_t*)str.ptr); }
|
||||||
else { hawk_rtx_freevaloocstr (rtx, a0, str.ptr); }
|
else { hawk_rtx_freevaloocstr (rtx, a0, str.ptr); }
|
||||||
|
|
||||||
if (fs_free) hawk_rtx_freevaloocstr (rtx, t0, fs_free);
|
if (fs_free)
|
||||||
|
{
|
||||||
|
if (byte_str && switch_fs_to_bchr)
|
||||||
|
hawk_rtx_freevalbcstr (rtx, t0, (hawk_bch_t*)fs_free);
|
||||||
|
else
|
||||||
|
hawk_rtx_freevaloocstr (rtx, t0, fs_free);
|
||||||
|
}
|
||||||
|
|
||||||
if (fs_rex_free)
|
if (fs_rex_free)
|
||||||
{
|
{
|
||||||
@ -1011,11 +1035,17 @@ oops:
|
|||||||
if (str.ptr)
|
if (str.ptr)
|
||||||
{
|
{
|
||||||
if (do_fld) { hawk_rtx_freemem (rtx, str.ptr); }
|
if (do_fld) { hawk_rtx_freemem (rtx, str.ptr); }
|
||||||
else if (byte_str) { hawk_rtx_freevalbcstr (rtx, a0, str.ptr); }
|
else if (byte_str) { hawk_rtx_freevalbcstr (rtx, a0, (hawk_bch_t*)str.ptr); }
|
||||||
else { hawk_rtx_freevaloocstr (rtx, a0, str.ptr); }
|
else { hawk_rtx_freevaloocstr (rtx, a0, str.ptr); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fs_free) hawk_rtx_freemem (rtx, fs_free);
|
if (fs_free)
|
||||||
|
{
|
||||||
|
if (byte_str && switch_fs_to_bchr)
|
||||||
|
hawk_rtx_freevalbcstr (rtx, t0, (hawk_bch_t*)fs_free);
|
||||||
|
else
|
||||||
|
hawk_rtx_freevaloocstr (rtx, t0, fs_free);
|
||||||
|
}
|
||||||
|
|
||||||
if (fs_rex_free)
|
if (fs_rex_free)
|
||||||
{
|
{
|
||||||
|
@ -211,10 +211,10 @@ char_t* tokenize_xchars (hawk_rtx_t* rtx, const char_t* s, hawk_oow_t len, const
|
|||||||
{
|
{
|
||||||
while (p < end)
|
while (p < end)
|
||||||
{
|
{
|
||||||
c = hawk_to_ooch_upper(*p);
|
c = to_xch_upper(*p);
|
||||||
for (d = delim; d < delim_end; d++)
|
for (d = delim; d < delim_end; d++)
|
||||||
{
|
{
|
||||||
if (c == hawk_to_ooch_upper(*d)) goto exit_loop;
|
if (c == to_xch_upper(*d)) goto exit_loop;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sp == HAWK_NULL) sp = p;
|
if (sp == HAWK_NULL) sp = p;
|
||||||
@ -246,7 +246,7 @@ char_t* tokenize_xchars (hawk_rtx_t* rtx, const char_t* s, hawk_oow_t len, const
|
|||||||
{
|
{
|
||||||
while (p < end)
|
while (p < end)
|
||||||
{
|
{
|
||||||
c = hawk_to_ooch_upper(*p);
|
c = to_xch_upper(*p);
|
||||||
if (is_xch_space(c))
|
if (is_xch_space(c))
|
||||||
{
|
{
|
||||||
p++;
|
p++;
|
||||||
@ -254,8 +254,7 @@ char_t* tokenize_xchars (hawk_rtx_t* rtx, const char_t* s, hawk_oow_t len, const
|
|||||||
}
|
}
|
||||||
for (d = delim; d < delim_end; d++)
|
for (d = delim; d < delim_end; d++)
|
||||||
{
|
{
|
||||||
if (c == hawk_to_ooch_upper(*d))
|
if (c == to_xch_upper(*d)) goto exit_loop;
|
||||||
goto exit_loop;
|
|
||||||
}
|
}
|
||||||
if (sp == HAWK_NULL) sp = p;
|
if (sp == HAWK_NULL) sp = p;
|
||||||
ep = p++;
|
ep = p++;
|
||||||
@ -290,7 +289,7 @@ exit_loop:
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
tok->ptr = (char_t*)sp;
|
tok->ptr = (char_t*)sp;
|
||||||
tok->len = ep - sp + 1;
|
tok->len = ep - sp + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if HAWK_NULL is returned, this function should not be called again */
|
/* if HAWK_NULL is returned, this function should not be called again */
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#undef char_t
|
#undef char_t
|
||||||
#undef xcs_t
|
#undef xcs_t
|
||||||
#undef is_xch_space
|
#undef is_xch_space
|
||||||
|
#undef to_xch_space
|
||||||
#undef match_rex_with_xcs
|
#undef match_rex_with_xcs
|
||||||
#undef split_xchars_to_fields
|
#undef split_xchars_to_fields
|
||||||
#undef tokenize_xchars
|
#undef tokenize_xchars
|
||||||
@ -38,6 +39,7 @@
|
|||||||
#define char_t hawk_bch_t
|
#define char_t hawk_bch_t
|
||||||
#define xcs_t hawk_bcs_t
|
#define xcs_t hawk_bcs_t
|
||||||
#define is_xch_space hawk_is_bch_space
|
#define is_xch_space hawk_is_bch_space
|
||||||
|
#define to_xch_upper hawk_to_bch_upper
|
||||||
#define match_rex_with_xcs hawk_rtx_matchrexwithbcs
|
#define match_rex_with_xcs hawk_rtx_matchrexwithbcs
|
||||||
|
|
||||||
#define split_xchars_to_fields hawk_rtx_fldbchars
|
#define split_xchars_to_fields hawk_rtx_fldbchars
|
||||||
@ -49,6 +51,7 @@
|
|||||||
#undef char_t
|
#undef char_t
|
||||||
#undef xcs_t
|
#undef xcs_t
|
||||||
#undef is_xch_space
|
#undef is_xch_space
|
||||||
|
#undef to_xch_upper
|
||||||
#undef match_rex_with_xcs
|
#undef match_rex_with_xcs
|
||||||
#undef split_xchars_to_fields
|
#undef split_xchars_to_fields
|
||||||
#undef tokenize_xchars
|
#undef tokenize_xchars
|
||||||
@ -57,6 +60,7 @@
|
|||||||
#define char_t hawk_uch_t
|
#define char_t hawk_uch_t
|
||||||
#define xcs_t hawk_ucs_t
|
#define xcs_t hawk_ucs_t
|
||||||
#define is_xch_space hawk_is_uch_space
|
#define is_xch_space hawk_is_uch_space
|
||||||
|
#define to_xch_upper hawk_to_uch_upper
|
||||||
#define match_rex_with_xcs hawk_rtx_matchrexwithucs
|
#define match_rex_with_xcs hawk_rtx_matchrexwithucs
|
||||||
|
|
||||||
#define split_xchars_to_fields hawk_rtx_flduchars
|
#define split_xchars_to_fields hawk_rtx_flduchars
|
||||||
|
@ -7356,7 +7356,7 @@ static hawk_val_t* eval_char (hawk_rtx_t* rtx, hawk_nde_t* nde)
|
|||||||
static hawk_val_t* eval_bchr (hawk_rtx_t* rtx, hawk_nde_t* nde)
|
static hawk_val_t* eval_bchr (hawk_rtx_t* rtx, hawk_nde_t* nde)
|
||||||
{
|
{
|
||||||
hawk_val_t* val;
|
hawk_val_t* val;
|
||||||
val = hawk_rtx_makebchrval(rtx, ((hawk_nde_char_t*)nde)->val);
|
val = hawk_rtx_makebchrval(rtx, ((hawk_nde_bchr_t*)nde)->val);
|
||||||
if (HAWK_UNLIKELY(!val)) ADJERR_LOC (rtx, &nde->loc);
|
if (HAWK_UNLIKELY(!val)) ADJERR_LOC (rtx, &nde->loc);
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
@ -340,7 +340,7 @@ static int print_expr (hawk_t* hawk, hawk_nde_t* nde)
|
|||||||
|
|
||||||
case HAWK_NDE_BCHR:
|
case HAWK_NDE_BCHR:
|
||||||
{
|
{
|
||||||
hawk_bch_t tmp = ((hawk_nde_char_t*)nde)->val;
|
hawk_bch_t tmp = ((hawk_nde_bchr_t*)nde)->val;
|
||||||
hawk_ooch_t buf[16];
|
hawk_ooch_t buf[16];
|
||||||
|
|
||||||
PUT_SRCSTR (hawk, HAWK_T("@b\'"));
|
PUT_SRCSTR (hawk, HAWK_T("@b\'"));
|
||||||
|
Loading…
Reference in New Issue
Block a user