removed special handling of $ in qse_strsubst() as literal $ can be denoted by 11789

This commit is contained in:
hyung-hwan 2018-04-03 09:33:50 +00:00
parent 5c297d784a
commit 70c787de9f
3 changed files with 42 additions and 12 deletions

View File

@ -950,6 +950,8 @@ QSE_EXPORT qse_size_t qse_wcsxvfmts (
* return buf; * return buf;
* } * }
* \endcode * \endcode
*
* Double dollars($$) translates a single literal dollar sign.
*/ */
QSE_EXPORT qse_size_t qse_mbsxsubst ( QSE_EXPORT qse_size_t qse_mbsxsubst (
qse_mchar_t* buf, qse_mchar_t* buf,
@ -1023,6 +1025,8 @@ QSE_EXPORT qse_size_t qse_mbsxnsubst (
* return buf; * return buf;
* } * }
* \endcode * \endcode
*
* Double dollars($$) translates a single literal dollar sign.
*/ */
QSE_EXPORT qse_size_t qse_wcsxsubst ( QSE_EXPORT qse_size_t qse_wcsxsubst (
qse_wchar_t* buf, qse_wchar_t* buf,

View File

@ -76,7 +76,7 @@ static const char_t* scan_dollar (
if (dfl) dfl->len = f - dfl->ptr; if (dfl) dfl->len = f - dfl->ptr;
return f + 1; return f + 1;
} }
else f++; else f++;
} }
} }
else if (*f == T('}')) else if (*f == T('}'))
@ -132,14 +132,7 @@ qse_size_t strxnsubst (
while (f < fend) while (f < fend)
{ {
if (*f == T('\\')) if (*f == T('$') && f < fend - 1)
{
/* get the escaped character and treat it normally.
* if the escaper is the last character, treat it
* normally also. */
if (f < fend - 1) f++;
}
else if (*f == T('$') && f < fend - 1)
{ {
if (*(f + 1) == T('{')) if (*(f + 1) == T('{'))
{ {
@ -167,7 +160,7 @@ qse_size_t strxnsubst (
} }
else if (*(f + 1) == T('$')) else if (*(f + 1) == T('$'))
{ {
/* $$ -> $. \$ is also $. */ /* $$ -> $. */
f++; f++;
} }
} }

View File

@ -246,8 +246,8 @@ qse_char_t* subst (qse_char_t* buf, qse_size_t bsz, const qse_cstr_t* ident, voi
return buf + qse_strxput (buf, bsz, QSE_T("coders")); return buf + qse_strxput (buf, bsz, QSE_T("coders"));
} }
/* don't do anything */ /*return buf; returning the buffer pointer will result in empty substitution and the default value won't be used */
return buf; return QSE_NULL; /* return NULL to take the default value if specified */
} }
static int test13 (void) static int test13 (void)
@ -269,6 +269,39 @@ static int test13 (void)
} }
qse_printf (QSE_T("]\n")); qse_printf (QSE_T("]\n"));
} }
qse_char_t buf2[48];
for (i = 0; i <= QSE_COUNTOF(buf2); i++)
{
qse_strcpy (buf2, QSE_T("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
qse_strxsubst (buf2, i, QSE_T("user=${USER},group=${GROUP},xxx=${USERX:=${GROUP:=default value}}"), subst, QSE_NULL);
qse_printf (QSE_T("bufsize=%02d, buf2=[%-49s] "), i, buf2);
qse_printf (QSE_T("["));
for (j = 0; j < QSE_COUNTOF(buf2); j++)
{
if (buf2[j] == QSE_T('\0')) qse_printf (QSE_T("*"));
else qse_printf (QSE_T("%c"), buf2[j]);
}
qse_printf (QSE_T("]\n"));
}
for (i = 0; i <= QSE_COUNTOF(buf2); i++)
{
qse_strcpy (buf2, QSE_T("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"));
qse_strxsubst (buf2, i, QSE_T("user=${USER},group=${GROUP},xxx=${USERX:=${GROUPX:=default value}}"), subst, QSE_NULL);
qse_printf (QSE_T("bufsize=%02d, buf2=[%-49s] "), i, buf2);
qse_printf (QSE_T("["));
for (j = 0; j < QSE_COUNTOF(buf2); j++)
{
if (buf2[j] == QSE_T('\0')) qse_printf (QSE_T("*"));
else qse_printf (QSE_T("%c"), buf2[j]);
}
qse_printf (QSE_T("]\n"));
}
return 0; return 0;
} }