added a callback called when a pair is read in by the xli format reader and the json format reader

This commit is contained in:
hyung-hwan 2018-01-19 15:57:44 +00:00
parent 2280811a8e
commit 3a2356737d
7 changed files with 80 additions and 28 deletions

View File

@ -2058,7 +2058,7 @@ QSE_EXPORT int qse_mbstoi (
const qse_mchar_t** end
);
QSE_EXPORT long qse_mbstol (
QSE_EXPORT long int qse_mbstol (
const qse_mchar_t* str,
int base,
const qse_mchar_t** end
@ -2070,7 +2070,7 @@ QSE_EXPORT unsigned int qse_mbstoui (
const qse_mchar_t** end
);
QSE_EXPORT unsigned long qse_mbstoul (
QSE_EXPORT unsigned long int qse_mbstoul (
const qse_mchar_t* str,
int base,
const qse_mchar_t** end
@ -2084,7 +2084,7 @@ QSE_EXPORT int qse_mbsxtoi (
const qse_mchar_t** end
);
QSE_EXPORT long qse_mbsxtol (
QSE_EXPORT long int qse_mbsxtol (
const qse_mchar_t* str,
qse_size_t len,
int base,
@ -2098,7 +2098,7 @@ QSE_EXPORT unsigned int qse_mbsxtoui (
const qse_mchar_t** end
);
QSE_EXPORT unsigned long qse_mbsxtoul (
QSE_EXPORT unsigned long int qse_mbsxtoul (
const qse_mchar_t* str,
qse_size_t len,
int base,
@ -2198,7 +2198,7 @@ QSE_EXPORT int qse_wcstoi (
const qse_wchar_t** end
);
QSE_EXPORT long qse_wcstol (
QSE_EXPORT long int qse_wcstol (
const qse_wchar_t* str,
int base,
const qse_wchar_t** end
@ -2210,7 +2210,7 @@ QSE_EXPORT unsigned int qse_wcstoui (
const qse_wchar_t** end
);
QSE_EXPORT unsigned long qse_wcstoul (
QSE_EXPORT unsigned long int qse_wcstoul (
const qse_wchar_t* str,
int base,
const qse_wchar_t** end
@ -2224,7 +2224,7 @@ QSE_EXPORT int qse_wcsxtoi (
const qse_wchar_t** end
);
QSE_EXPORT long qse_wcsxtol (
QSE_EXPORT long int qse_wcsxtol (
const qse_wchar_t* str,
qse_size_t len,
int base,
@ -2238,7 +2238,7 @@ QSE_EXPORT unsigned int qse_wcsxtoui (
const qse_wchar_t** end
);
QSE_EXPORT unsigned long qse_wcsxtoul (
QSE_EXPORT unsigned long int qse_wcsxtoul (
const qse_wchar_t* str,
qse_size_t len,
int base,

View File

@ -119,7 +119,9 @@ enum qse_xli_opt_t
*/
QSE_XLI_ROOTXTNSIZE,
QSE_XLI_KEYSPLITTER
QSE_XLI_KEYSPLITTER,
QSE_XLI_CBS
};
typedef enum qse_xli_opt_t qse_xli_opt_t;
@ -163,6 +165,7 @@ enum qse_xli_trait_t
};
typedef enum qse_xli_trait_t qse_xli_trait_t;
typedef struct qse_xli_val_t qse_xli_val_t;
typedef struct qse_xli_nil_t qse_xli_nil_t;
typedef struct qse_xli_true_t qse_xli_true_t;
@ -448,6 +451,23 @@ struct qse_xli_scm_t
typedef struct qse_xli_scm_t qse_xli_scm_t;
/* --------------------------------------------------------------------- */
typedef void (*qse_xli_pair_read_cb_t) (
qse_xli_t* xli,
qse_xli_pair_t* pair,
qse_xli_loc_t* loc
);
struct qse_xli_cbs_t
{
qse_xli_pair_read_cb_t pair_read;
};
typedef struct qse_xli_cbs_t qse_xli_cbs_t;
#if defined(__cplusplus)
extern "C" {
#endif

View File

@ -40,9 +40,9 @@ int qse_mbstoi (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
return v;
}
long qse_mbstol (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
long int qse_mbstol (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
{
long v;
long int v;
QSE_MBSTONUM (v, mbs, end, base, 1);
return v;
}
@ -54,9 +54,9 @@ unsigned int qse_mbstoui (const qse_mchar_t* mbs, int base, const qse_mchar_t**
return v;
}
unsigned long qse_mbstoul (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
unsigned long int qse_mbstoul (const qse_mchar_t* mbs, int base, const qse_mchar_t** end)
{
unsigned long v;
unsigned long int v;
QSE_MBSTONUM (v, mbs, end, base, 0);
return v;
}
@ -70,9 +70,9 @@ int qse_mbsxtoi (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mch
return v;
}
long qse_mbsxtol (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mchar_t** end)
long int qse_mbsxtol (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mchar_t** end)
{
long v;
long int v;
QSE_MBSXTONUM (v, mbs, len, end, base, 1);
return v;
}
@ -84,9 +84,9 @@ unsigned int qse_mbsxtoui (const qse_mchar_t* mbs, qse_size_t len, int base, con
return v;
}
unsigned long qse_mbsxtoul (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mchar_t** end)
unsigned long int qse_mbsxtoul (const qse_mchar_t* mbs, qse_size_t len, int base, const qse_mchar_t** end)
{
unsigned long v;
unsigned long int v;
QSE_MBSXTONUM (v, mbs, len, end, base, 0);
return v;
}
@ -192,9 +192,9 @@ int qse_wcstoi (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
return v;
}
long qse_wcstol (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
long int qse_wcstol (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
{
long v;
long int v;
QSE_WCSTONUM (v, wcs, end, base, 1);
return v;
}
@ -206,9 +206,9 @@ unsigned int qse_wcstoui (const qse_wchar_t* wcs, int base, const qse_wchar_t**
return v;
}
unsigned long qse_wcstoul (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
unsigned long int qse_wcstoul (const qse_wchar_t* wcs, int base, const qse_wchar_t** end)
{
unsigned long v;
unsigned long int v;
QSE_WCSTONUM (v, wcs, end, base, 0);
return v;
}
@ -222,9 +222,9 @@ int qse_wcsxtoi (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wch
return v;
}
long qse_wcsxtol (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wchar_t** end)
long int qse_wcsxtol (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wchar_t** end)
{
long v;
long int v;
QSE_WCSXTONUM (v, wcs, len, end, base, 1);
return v;
}
@ -236,9 +236,9 @@ unsigned int qse_wcsxtoui (const qse_wchar_t* wcs, qse_size_t len, int base, con
return v;
}
unsigned long qse_wcsxtoul (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wchar_t** end)
unsigned long int qse_wcsxtoul (const qse_wchar_t* wcs, qse_size_t len, int base, const qse_wchar_t** end)
{
unsigned long v;
unsigned long int v;
QSE_WCSXTONUM (v, wcs, len, end, base, 0);
return v;
}

View File

@ -690,15 +690,22 @@ static int __read_array (qse_xli_t* xli)
qse_size_t index = 0;
qse_char_t key[64];
if (MATCH(xli, QSE_XLI_TOK_RBRACK)) return 0; // empty array
if (MATCH(xli, QSE_XLI_TOK_RBRACK)) return 0; /* empty array */
while (1)
{
qse_xli_pair_t* p;
qse_xli_loc_t ploc;
val = __read_value(xli);
if (!val) return -1;
ploc = xli->tok.loc;
qse_strxfmt (key, QSE_COUNTOF(key), QSE_T("%zu"), index);
if (!qse_xli_insertpair (xli, xli->parlink->list, QSE_NULL, key, QSE_NULL, QSE_NULL, val)) return -1;
p = qse_xli_insertpair (xli, xli->parlink->list, QSE_NULL, key, QSE_NULL, QSE_NULL, val);
if (!p) return -1;
if (xli->opt.cbs.pair_read) xli->opt.cbs.pair_read (xli, p, &ploc);
index++;
if (get_token(xli) <= -1) return -1;
@ -759,15 +766,22 @@ static int __read_list (qse_xli_t* xli)
else if (/*MATCH(xli, QSE_XLI_TOK_IDENT) ||*/ MATCH(xli, QSE_XLI_TOK_DQSTR) || MATCH(xli, QSE_XLI_TOK_SQSTR))
{
rpair_t rpair;
qse_xli_pair_t* p;
qse_xli_loc_t ploc;
ploc = xli->tok.loc;
if (read_pair(xli, &rpair) <= -1) return -1;
if (!qse_xli_insertpair(xli, xli->parlink->list, QSE_NULL, rpair.key, QSE_NULL, QSE_NULL, rpair.val))
p = qse_xli_insertpair(xli, xli->parlink->list, QSE_NULL, rpair.key, QSE_NULL, QSE_NULL, rpair.val);
if (!p)
{
QSE_MMGR_FREE (xli->mmgr, rpair.key);
qse_xli_freeval (xli, rpair.val);
return -1;
}
if (xli->opt.cbs.pair_read) xli->opt.cbs.pair_read (xli, p, &ploc);
/* clear the duplicated key. the key is also duplicated in qse_xli_insertpair(). don't need it */
QSE_MMGR_FREE (xli->mmgr, rpair.key);

View File

@ -750,6 +750,7 @@ static int read_pair (qse_xli_t* xli, const qse_char_t* keytag, const qse_xli_sc
const qse_xli_scm_t* scm = QSE_NULL;
int key_nodup = 0, key_alias = 0, val_iffy = 0;
key.ptr = QSE_NULL;
name = QSE_NULL;
@ -889,6 +890,8 @@ static int read_pair (qse_xli_t* xli, const qse_char_t* keytag, const qse_xli_sc
pair = qse_xli_insertpair(xli, parlist, QSE_NULL, key.ptr, name, keytag, v);
if (pair == QSE_NULL) goto oops;
if (xli->opt.cbs.pair_read) xli->opt.cbs.pair_read (xli, pair, &kloc);
if (get_token (xli) <= -1) goto oops; /* skip the value */
if (!MATCH(xli, QSE_XLI_TOK_SEMICOLON))
@ -915,6 +918,8 @@ static int read_pair (qse_xli_t* xli, const qse_char_t* keytag, const qse_xli_sc
pair = qse_xli_insertpairwithstr(xli, parlist, QSE_NULL, key.ptr, name, keytag, QSE_STR_XSTR(xli->tok.name), strtag);
if (pair == QSE_NULL) goto oops;
if (xli->opt.cbs.pair_read) xli->opt.cbs.pair_read (xli, pair, &kloc);
if (MATCH(xli, QSE_XLI_TOK_NSTR))
{
((qse_xli_str_t*)pair->val)->flags |= QSE_XLI_STR_NSTR;
@ -1005,6 +1010,8 @@ static int read_pair (qse_xli_t* xli, const qse_char_t* keytag, const qse_xli_sc
pair = qse_xli_insertpairwithemptylist(xli, parlist, QSE_NULL, key.ptr, name, keytag);
if (pair == QSE_NULL) goto oops;
if (xli->opt.cbs.pair_read) xli->opt.cbs.pair_read (xli, pair, &kloc);
/* skip validations of child pairs if the schema for the
* current pair is set with QSE_XLI_SCM_VALIFFY.
* the schema for the child pairs, if specified, must not
@ -1050,6 +1057,8 @@ static int read_pair (qse_xli_t* xli, const qse_char_t* keytag, const qse_xli_sc
pair = qse_xli_insertpair (xli, parlist, QSE_NULL, key.ptr, name, keytag, (qse_xli_val_t*)&xli->root->xnil);
if (pair == QSE_NULL) goto oops;
if (xli->opt.cbs.pair_read) xli->opt.cbs.pair_read (xli, pair, &kloc);
/* skip the semicolon */
if (get_token (xli) <= -1) goto oops;

View File

@ -146,6 +146,10 @@ int qse_xli_setopt (qse_xli_t* xli, qse_xli_opt_t id, const void* value)
case QSE_XLI_KEYSPLITTER:
xli->opt.key_splitter = *(const qse_char_t*)value;
return 0;
case QSE_XLI_CBS:
xli->opt.cbs = *(qse_xli_cbs_t*)value;
return 0;
}
qse_xli_seterrnum (xli, QSE_XLI_EINVAL, QSE_NULL);
@ -171,6 +175,10 @@ int qse_xli_getopt (qse_xli_t* xli, qse_xli_opt_t id, void* value)
case QSE_XLI_KEYSPLITTER:
*(qse_char_t*)value = xli->opt.key_splitter;
return 0;
case QSE_XLI_CBS:
*(qse_xli_cbs_t*)value = xli->opt.cbs;
return 0;
};
qse_xli_seterrnum (xli, QSE_XLI_EINVAL, QSE_NULL);

View File

@ -103,6 +103,7 @@ struct qse_xli_t
qse_size_t pair_xtnsize;
qse_size_t root_xtnsize;
qse_char_t key_splitter; /**< character to use to split a key in the fqpn format */
qse_xli_cbs_t cbs;
int (*strcmp) (const qse_char_t* s1, const qse_char_t* s2);
int (*strxcmp) (const qse_char_t* s1, qse_size_t len1, const qse_char_t* s2);