diff --git a/qse/include/qse/cmn/str.h b/qse/include/qse/cmn/str.h index 57b586c2..29069773 100644 --- a/qse/include/qse/cmn/str.h +++ b/qse/include/qse/cmn/str.h @@ -950,6 +950,8 @@ QSE_EXPORT qse_size_t qse_wcsxvfmts ( * return buf; * } * \endcode + * + * Double dollars($$) translates a single literal dollar sign. */ QSE_EXPORT qse_size_t qse_mbsxsubst ( qse_mchar_t* buf, @@ -1023,6 +1025,8 @@ QSE_EXPORT qse_size_t qse_mbsxnsubst ( * return buf; * } * \endcode + * + * Double dollars($$) translates a single literal dollar sign. */ QSE_EXPORT qse_size_t qse_wcsxsubst ( qse_wchar_t* buf, diff --git a/qse/lib/cmn/str-subst.h b/qse/lib/cmn/str-subst.h index 13109656..d37e7676 100644 --- a/qse/lib/cmn/str-subst.h +++ b/qse/lib/cmn/str-subst.h @@ -76,7 +76,7 @@ static const char_t* scan_dollar ( if (dfl) dfl->len = f - dfl->ptr; return f + 1; } - else f++; + else f++; } } else if (*f == T('}')) @@ -132,14 +132,7 @@ qse_size_t strxnsubst ( while (f < fend) { - if (*f == T('\\')) - { - /* 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 == T('$') && f < fend - 1) { if (*(f + 1) == T('{')) { @@ -167,7 +160,7 @@ qse_size_t strxnsubst ( } else if (*(f + 1) == T('$')) { - /* $$ -> $. \$ is also $. */ + /* $$ -> $. */ f++; } } diff --git a/qse/samples/cmn/str01.c b/qse/samples/cmn/str01.c index b7d2fbfa..e3707e4c 100644 --- a/qse/samples/cmn/str01.c +++ b/qse/samples/cmn/str01.c @@ -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")); } - /* don't do anything */ - return buf; + /*return buf; returning the buffer pointer will result in empty substitution and the default value won't be used */ + return QSE_NULL; /* return NULL to take the default value if specified */ } static int test13 (void) @@ -269,6 +269,39 @@ static int test13 (void) } 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; }