fixed the bug of affecting the parameter in toupper and tolower in awk.

also enhanced them to support byte strings
This commit is contained in:
hyung-hwan 2019-04-22 09:03:02 +00:00
parent b86ea48c86
commit c80f179366
2 changed files with 47 additions and 29 deletions

View File

@ -841,26 +841,35 @@ int qse_awk_fnc_tolower (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
qse_size_t nargs;
qse_size_t i;
qse_awk_val_t* a0, * r;
qse_cstr_t str;
nargs = qse_awk_rtx_getnargs(rtx);
QSE_ASSERT (nargs == 1);
a0 = qse_awk_rtx_getarg (rtx, 0);
str.ptr = qse_awk_rtx_getvalstr(rtx, a0, &str.len);
if (str.ptr == QSE_NULL) return -1;
for (i = 0; i < str.len; i++) str.ptr[i] = QSE_AWK_TOLOWER (rtx->awk, str.ptr[i]);
r = qse_awk_rtx_makestrvalwithxstr(rtx, &str);
if (r == QSE_NULL)
if (QSE_AWK_RTX_GETVALTYPE(rtx, a0) == QSE_AWK_VAL_MBS)
{
qse_awk_rtx_freevalstr (rtx, a0, str.ptr);
return -1;
qse_mcstr_t str;
str.ptr = qse_awk_rtx_getvalmbs(rtx, a0, &str.len);
if (!str.ptr) return -1;
r = qse_awk_rtx_makembsvalwithmxstr(rtx, &str);
qse_awk_rtx_freevalmbs (rtx, a0, str.ptr);
if (!r) return -1;
str.ptr = ((qse_awk_val_mbs_t*)r)->val.ptr;
str.len = ((qse_awk_val_mbs_t*)r)->val.len;
for (i = 0; i < str.len; i++) str.ptr[i] = QSE_AWK_TOMLOWER(rtx->awk, str.ptr[i]);
}
else
{
qse_cstr_t str;
str.ptr = qse_awk_rtx_getvalstr(rtx, a0, &str.len);
if (!str.ptr) return -1;
r = qse_awk_rtx_makestrvalwithxstr(rtx, &str);
qse_awk_rtx_freevalstr (rtx, a0, str.ptr);
if (!r) return -1;
str.ptr = ((qse_awk_val_str_t*)r)->val.ptr;
str.len = ((qse_awk_val_str_t*)r)->val.len;
for (i = 0; i < str.len; i++) str.ptr[i] = QSE_AWK_TOLOWER(rtx->awk, str.ptr[i]);
}
qse_awk_rtx_freevalstr (rtx, a0, str.ptr);
qse_awk_rtx_setretval (rtx, r);
return 0;
}
@ -870,26 +879,35 @@ int qse_awk_fnc_toupper (qse_awk_rtx_t* rtx, const qse_awk_fnc_info_t* fi)
qse_size_t nargs;
qse_size_t i;
qse_awk_val_t* a0, * r;
qse_cstr_t str;
nargs = qse_awk_rtx_getnargs(rtx);
QSE_ASSERT (nargs == 1);
a0 = qse_awk_rtx_getarg(rtx, 0);
str.ptr = qse_awk_rtx_getvalstr(rtx, a0, &str.len);
if (str.ptr == QSE_NULL) return -1;
for (i = 0; i < str.len; i++) str.ptr[i] = QSE_AWK_TOUPPER (rtx->awk, str.ptr[i]);
r = qse_awk_rtx_makestrvalwithxstr (rtx, &str);
if (r == QSE_NULL)
a0 = qse_awk_rtx_getarg (rtx, 0);
if (QSE_AWK_RTX_GETVALTYPE(rtx, a0) == QSE_AWK_VAL_MBS)
{
qse_awk_rtx_freevalstr (rtx, a0, str.ptr);
return -1;
qse_mcstr_t str;
str.ptr = qse_awk_rtx_getvalmbs(rtx, a0, &str.len);
if (!str.ptr) return -1;
r = qse_awk_rtx_makembsvalwithmxstr(rtx, &str);
qse_awk_rtx_freevalmbs (rtx, a0, str.ptr);
if (!r) return -1;
str.ptr = ((qse_awk_val_mbs_t*)r)->val.ptr;
str.len = ((qse_awk_val_mbs_t*)r)->val.len;
for (i = 0; i < str.len; i++) str.ptr[i] = QSE_AWK_TOMUPPER(rtx->awk, str.ptr[i]);
}
else
{
qse_cstr_t str;
str.ptr = qse_awk_rtx_getvalstr(rtx, a0, &str.len);
if (!str.ptr) return -1;
r = qse_awk_rtx_makestrvalwithxstr(rtx, &str);
qse_awk_rtx_freevalstr (rtx, a0, str.ptr);
if (!r) return -1;
str.ptr = ((qse_awk_val_str_t*)r)->val.ptr;
str.len = ((qse_awk_val_str_t*)r)->val.len;
for (i = 0; i < str.len; i++) str.ptr[i] = QSE_AWK_TOUPPER(rtx->awk, str.ptr[i]);
}
qse_awk_rtx_freevalstr (rtx, a0, str.ptr);
qse_awk_rtx_setretval (rtx, r);
return 0;
}

View File

@ -1696,7 +1696,7 @@ int qse_awk_rtx_valtonum (qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_awk_in
case QSE_AWK_VAL_STR:
{
return qse_awk_rtx_strtonum (
return qse_awk_rtx_strtonum(
rtx,
QSE_AWK_RTX_STRTONUM_MAKE_OPTION(0, 0),
((qse_awk_val_str_t*)v)->val.ptr,
@ -1707,7 +1707,7 @@ int qse_awk_rtx_valtonum (qse_awk_rtx_t* rtx, const qse_awk_val_t* v, qse_awk_in
case QSE_AWK_VAL_MBS:
{
return qse_awk_rtx_mbstonum (
return qse_awk_rtx_mbstonum(
rtx,
QSE_AWK_RTX_STRTONUM_MAKE_OPTION(0, 0),
((qse_awk_val_mbs_t*)v)->val.ptr,