|
|
|
@ -28,14 +28,12 @@
|
|
|
|
|
/** \file
|
|
|
|
|
* This file provides various functions, types, macros for string manipulation.
|
|
|
|
|
*
|
|
|
|
|
* The #qse_cstr_t type and the #qse_xstr_t defined in <qse/types.h> help you
|
|
|
|
|
* The #qse_xstr_t type and the #qse_xstr_t defined in <qse/types.h> help you
|
|
|
|
|
* deal with a string pointer and length in a structure.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/** string pointer and length as a aggregate */
|
|
|
|
|
#define QSE_MBS_XSTR(s) (&((s)->val))
|
|
|
|
|
/** constant string pointer and length as a aggregate */
|
|
|
|
|
#define QSE_MBS_CSTR(s) ((qse_mcstr_t*)&((s)->val))
|
|
|
|
|
/** string length */
|
|
|
|
|
#define QSE_MBS_LEN(s) ((s)->val.len)
|
|
|
|
|
/** string pointer */
|
|
|
|
@ -51,8 +49,6 @@
|
|
|
|
|
|
|
|
|
|
/** string pointer and length as a aggregate */
|
|
|
|
|
#define QSE_WCS_XSTR(s) (&((s)->val))
|
|
|
|
|
/** constant string pointer and length as a aggregate */
|
|
|
|
|
#define QSE_WCS_CSTR(s) ((qse_wcstr_t*)&((s)->val))
|
|
|
|
|
/** string length */
|
|
|
|
|
#define QSE_WCS_LEN(s) ((s)->val.len)
|
|
|
|
|
/** string pointer */
|
|
|
|
@ -81,7 +77,6 @@ typedef qse_size_t (*qse_wcs_sizer_t) (
|
|
|
|
|
|
|
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
|
# define QSE_STR_XSTR(s) ((qse_xstr_t*)QSE_MBS_XSTR(s))
|
|
|
|
|
# define QSE_STR_CSTR(s) ((qse_cstr_t*)QSE_MBS_XSTR(s))
|
|
|
|
|
# define QSE_STR_LEN(s) QSE_MBS_LEN(s)
|
|
|
|
|
# define QSE_STR_PTR(s) QSE_MBS_PTR(s)
|
|
|
|
|
# define QSE_STR_CPTR(s,idx) QSE_MBS_CPTR(s,idx)
|
|
|
|
@ -92,7 +87,6 @@ typedef qse_size_t (*qse_wcs_sizer_t) (
|
|
|
|
|
# define qse_str_sizer_t qse_mbs_sizer_t
|
|
|
|
|
#else
|
|
|
|
|
# define QSE_STR_XSTR(s) ((qse_xstr_t*)QSE_WCS_XSTR(s))
|
|
|
|
|
# define QSE_STR_CSTR(s) ((qse_cstr_t*)QSE_WCS_XSTR(s))
|
|
|
|
|
# define QSE_STR_LEN(s) QSE_WCS_LEN(s)
|
|
|
|
|
# define QSE_STR_PTR(s) QSE_WCS_PTR(s)
|
|
|
|
|
# define QSE_STR_CPTR(s,idx) QSE_WCS_CPTR(s,idx)
|
|
|
|
@ -137,7 +131,7 @@ struct qse_wcs_t
|
|
|
|
|
typedef qse_mchar_t* (*qse_mbssubst_t) (
|
|
|
|
|
qse_mchar_t* buf,
|
|
|
|
|
qse_size_t bsz,
|
|
|
|
|
const qse_mcstr_t* ident,
|
|
|
|
|
const qse_mxstr_t* ident,
|
|
|
|
|
void* ctx
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
@ -148,7 +142,7 @@ typedef qse_mchar_t* (*qse_mbssubst_t) (
|
|
|
|
|
typedef qse_wchar_t* (*qse_wcssubst_t) (
|
|
|
|
|
qse_wchar_t* buf,
|
|
|
|
|
qse_size_t bsz,
|
|
|
|
|
const qse_wcstr_t* ident,
|
|
|
|
|
const qse_wxstr_t* ident,
|
|
|
|
|
void* ctx
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
@ -591,25 +585,25 @@ QSE_EXPORT qse_size_t qse_wcsfcpy (
|
|
|
|
|
/**
|
|
|
|
|
* The qse_mbsfncpy() function formats a string by position.
|
|
|
|
|
* It differs from qse_mbsfcpy() in that \a str is an array of the
|
|
|
|
|
* #qse_mcstr_t type.
|
|
|
|
|
* #qse_mxstr_t type.
|
|
|
|
|
* \sa qse_mbsfcpy, qse_mbsxfcpy, qse_mbsxfncpy
|
|
|
|
|
*/
|
|
|
|
|
QSE_EXPORT qse_size_t qse_mbsfncpy (
|
|
|
|
|
qse_mchar_t* buf,
|
|
|
|
|
const qse_mchar_t* fmt,
|
|
|
|
|
const qse_mcstr_t str[]
|
|
|
|
|
const qse_mxstr_t str[]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The qse_wcsfncpy() function formats a string by position.
|
|
|
|
|
* It differs from qse_wcsfcpy() in that \a str is an array of the
|
|
|
|
|
* #qse_wcstr_t type.
|
|
|
|
|
* #qse_wxstr_t type.
|
|
|
|
|
* \sa qse_wcsfcpy, qse_wcsxfcpy, qse_wcsxfncpy
|
|
|
|
|
*/
|
|
|
|
|
QSE_EXPORT qse_size_t qse_wcsfncpy (
|
|
|
|
|
qse_wchar_t* buf,
|
|
|
|
|
const qse_wchar_t* fmt,
|
|
|
|
|
const qse_wcstr_t str[]
|
|
|
|
|
const qse_wxstr_t str[]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -651,27 +645,27 @@ QSE_EXPORT qse_size_t qse_wcsxfcpy (
|
|
|
|
|
/**
|
|
|
|
|
* The qse_mbsxfncpy() function formats a string by position.
|
|
|
|
|
* It differs from qse_strfcpy() in that \a buf is length-bounded of \a bsz
|
|
|
|
|
* characters and \a str is an array of the #qse_mcstr_t type.
|
|
|
|
|
* characters and \a str is an array of the #qse_mxstr_t type.
|
|
|
|
|
* \sa qse_mbsfcpy, qse_mbsfncpy, qse_mbsxfcpy
|
|
|
|
|
*/
|
|
|
|
|
QSE_EXPORT qse_size_t qse_mbsxfncpy (
|
|
|
|
|
qse_mchar_t* buf,
|
|
|
|
|
qse_size_t bsz,
|
|
|
|
|
const qse_mchar_t* fmt,
|
|
|
|
|
const qse_mcstr_t str[]
|
|
|
|
|
const qse_mxstr_t str[]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The qse_wcsxfncpy() function formats a string by position.
|
|
|
|
|
* It differs from qse_strfcpy() in that \a buf is length-bounded of \a bsz
|
|
|
|
|
* characters and \a str is an array of the #qse_wcstr_t type.
|
|
|
|
|
* characters and \a str is an array of the #qse_wxstr_t type.
|
|
|
|
|
* \sa qse_wcsfcpy, qse_wcsfncpy, qse_wcsxfcpy
|
|
|
|
|
*/
|
|
|
|
|
QSE_EXPORT qse_size_t qse_wcsxfncpy (
|
|
|
|
|
qse_wchar_t* buf,
|
|
|
|
|
qse_size_t bsz,
|
|
|
|
|
const qse_wchar_t* fmt,
|
|
|
|
|
const qse_wcstr_t str[]
|
|
|
|
|
const qse_wxstr_t str[]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
@ -787,7 +781,7 @@ QSE_EXPORT qse_size_t qse_wcsxvfmt (
|
|
|
|
|
* \a bsz by substituting new values for ${} segments within it. The actual
|
|
|
|
|
* substitution is made by invoking the callback function \a subst.
|
|
|
|
|
* \code
|
|
|
|
|
* qse_mchar_t* subst (qse_mchar_t* buf, qse_size_t bsz, const qse_mcstr_t* ident, void* ctx)
|
|
|
|
|
* qse_mchar_t* subst (qse_mchar_t* buf, qse_size_t bsz, const qse_mxstr_t* ident, void* ctx)
|
|
|
|
|
* {
|
|
|
|
|
* if (qse_mbsxcmp (ident->ptr, ident->len, QSE_MT("USER")) == 0)
|
|
|
|
|
* return buf + qse_mbsxput (buf, bsz, QSE_MT("sam"));
|
|
|
|
@ -809,7 +803,7 @@ QSE_EXPORT qse_size_t qse_wcsxvfmt (
|
|
|
|
|
* if the buffer points to #QSE_MBSSUBST_NOBUF as shown belown.
|
|
|
|
|
*
|
|
|
|
|
* \code
|
|
|
|
|
* qse_mchar_t* subst (qse_mchar_t* buf, qse_size_t bsz, const qse_mcstr_t* ident, void* ctx)
|
|
|
|
|
* qse_mchar_t* subst (qse_mchar_t* buf, qse_size_t bsz, const qse_mxstr_t* ident, void* ctx)
|
|
|
|
|
* {
|
|
|
|
|
* if (qse_mcsxcmp (ident->ptr, ident->len, QSE_MT("USER")) == 0)
|
|
|
|
|
* return buf + (buf == QSE_MBSSUBST_NOBUF? 3: qse_mcsxput (buf, bsz, QSE_MT("sam")));
|
|
|
|
@ -829,7 +823,7 @@ QSE_EXPORT qse_size_t qse_wcsxvfmt (
|
|
|
|
|
* recursively.
|
|
|
|
|
*
|
|
|
|
|
* \code
|
|
|
|
|
* qse_mchar_t* subst (qse_mchar_t* buf, qse_size_t bsz, const qse_mcstr_t* ident, void* ctx)
|
|
|
|
|
* qse_mchar_t* subst (qse_mchar_t* buf, qse_size_t bsz, const qse_mxstr_t* ident, void* ctx)
|
|
|
|
|
* {
|
|
|
|
|
* if (qse_mbsxcmp (ident->ptr, ident->len, QSE_MT("USER")) == 0)
|
|
|
|
|
* return QSE_NULL;
|
|
|
|
@ -861,7 +855,7 @@ QSE_EXPORT qse_size_t qse_mbsxnsubst (
|
|
|
|
|
* \a bsz by substituting new values for ${} segments within it. The actual
|
|
|
|
|
* substitution is made by invoking the callback function \a subst.
|
|
|
|
|
* \code
|
|
|
|
|
* qse_wchar_t* subst (qse_wchar_t* buf, qse_size_t bsz, const qse_wcstr_t* ident, void* ctx)
|
|
|
|
|
* qse_wchar_t* subst (qse_wchar_t* buf, qse_size_t bsz, const qse_wxstr_t* ident, void* ctx)
|
|
|
|
|
* {
|
|
|
|
|
* if (qse_wcsxcmp (ident->ptr, ident->len, QSE_WT("USER")) == 0)
|
|
|
|
|
* return buf + qse_wcsxput (buf, bsz, QSE_WT("sam"));
|
|
|
|
@ -882,7 +876,7 @@ QSE_EXPORT qse_size_t qse_mbsxnsubst (
|
|
|
|
|
* above can be extended to return the buffer pointer without actual copying
|
|
|
|
|
*
|
|
|
|
|
* \code
|
|
|
|
|
* qse_mchar_t* subst (qse_mchar_t* buf, qse_size_t bsz, const qse_wcstr_t* ident, void* ctx)
|
|
|
|
|
* qse_mchar_t* subst (qse_mchar_t* buf, qse_size_t bsz, const qse_wxstr_t* ident, void* ctx)
|
|
|
|
|
* {
|
|
|
|
|
* if (qse_wcsxcmp (ident->ptr, ident->len, QSE_WT("USER")) == 0)
|
|
|
|
|
* return buf + (buf == QSE_WCSSUBST_NOBUF? 3: qse_wcsxput (buf, bsz, QSE_WT("sam")));
|
|
|
|
@ -902,7 +896,7 @@ QSE_EXPORT qse_size_t qse_mbsxnsubst (
|
|
|
|
|
* recursively.
|
|
|
|
|
*
|
|
|
|
|
* \code
|
|
|
|
|
* qse_mchar_t* subst (qse_mchar_t* buf, qse_size_t bsz, const qse_wcstr_t* ident, void* ctx)
|
|
|
|
|
* qse_mchar_t* subst (qse_mchar_t* buf, qse_size_t bsz, const qse_wxstr_t* ident, void* ctx)
|
|
|
|
|
* {
|
|
|
|
|
* if (qse_wcsxcmp (ident->ptr, ident->len, QSE_WT("USER")) == 0)
|
|
|
|
|
* return QSE_NULL;
|
|
|
|
@ -1294,23 +1288,23 @@ QSE_EXPORT qse_wchar_t* qse_wcsadup (
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
QSE_EXPORT qse_mchar_t* qse_mcstrdup (
|
|
|
|
|
const qse_mcstr_t* str,
|
|
|
|
|
const qse_mxstr_t* str,
|
|
|
|
|
qse_mmgr_t* mmgr
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
QSE_EXPORT qse_mchar_t* qse_mcstradup (
|
|
|
|
|
const qse_mcstr_t str[],
|
|
|
|
|
const qse_mxstr_t str[],
|
|
|
|
|
qse_size_t* len,
|
|
|
|
|
qse_mmgr_t* mmgr
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
QSE_EXPORT qse_wchar_t* qse_wcstrdup (
|
|
|
|
|
const qse_wcstr_t* str,
|
|
|
|
|
const qse_wxstr_t* str,
|
|
|
|
|
qse_mmgr_t* mmgr
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
QSE_EXPORT qse_wchar_t* qse_wcstradup (
|
|
|
|
|
const qse_wcstr_t str[],
|
|
|
|
|
const qse_wxstr_t str[],
|
|
|
|
|
qse_size_t* len,
|
|
|
|
|
qse_mmgr_t* mmgr
|
|
|
|
|
);
|
|
|
|
@ -2290,14 +2284,14 @@ QSE_EXPORT int qse_wcsspltrn (
|
|
|
|
|
QSE_EXPORT qse_mchar_t* qse_mbstok (
|
|
|
|
|
const qse_mchar_t* s,
|
|
|
|
|
const qse_mchar_t* delim,
|
|
|
|
|
qse_mcstr_t* tok
|
|
|
|
|
qse_mxstr_t* tok
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
QSE_EXPORT qse_mchar_t* qse_mbsxtok (
|
|
|
|
|
const qse_mchar_t* s,
|
|
|
|
|
qse_size_t len,
|
|
|
|
|
const qse_mchar_t* delim,
|
|
|
|
|
qse_mcstr_t* tok
|
|
|
|
|
qse_mxstr_t* tok
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
QSE_EXPORT qse_mchar_t* qse_mbsxntok (
|
|
|
|
@ -2305,20 +2299,20 @@ QSE_EXPORT qse_mchar_t* qse_mbsxntok (
|
|
|
|
|
qse_size_t len,
|
|
|
|
|
const qse_mchar_t* delim,
|
|
|
|
|
qse_size_t delim_len,
|
|
|
|
|
qse_mcstr_t* tok
|
|
|
|
|
qse_mxstr_t* tok
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
QSE_EXPORT qse_wchar_t* qse_wcstok (
|
|
|
|
|
const qse_wchar_t* s,
|
|
|
|
|
const qse_wchar_t* delim,
|
|
|
|
|
qse_wcstr_t* tok
|
|
|
|
|
qse_wxstr_t* tok
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
QSE_EXPORT qse_wchar_t* qse_wcsxtok (
|
|
|
|
|
const qse_wchar_t* s,
|
|
|
|
|
qse_size_t len,
|
|
|
|
|
const qse_wchar_t* delim,
|
|
|
|
|
qse_wcstr_t* tok
|
|
|
|
|
qse_wxstr_t* tok
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
QSE_EXPORT qse_wchar_t* qse_wcsxntok (
|
|
|
|
@ -2326,7 +2320,7 @@ QSE_EXPORT qse_wchar_t* qse_wcsxntok (
|
|
|
|
|
qse_size_t len,
|
|
|
|
|
const qse_wchar_t* delim,
|
|
|
|
|
qse_size_t delim_len,
|
|
|
|
|
qse_wcstr_t* tok
|
|
|
|
|
qse_wxstr_t* tok
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
#if defined(QSE_CHAR_IS_MCHAR)
|
|
|
|
|