touched up qse_xli_setpairwithstr() a bit

This commit is contained in:
hyung-hwan 2018-01-22 09:38:44 +00:00
parent fc1748ccd0
commit c0a072a054
2 changed files with 34 additions and 37 deletions

View File

@ -735,6 +735,10 @@ QSE_EXPORT qse_xli_pair_t* qse_xli_findpair (
const qse_char_t* fqpn const qse_char_t* fqpn
); );
/**
* The qse_xli_setpairwithstr() finds an existing pair with the fully qualified
* pair name and updates its value with a new string value.
*/
QSE_EXPORT qse_xli_pair_t* qse_xli_setpairwithstr ( QSE_EXPORT qse_xli_pair_t* qse_xli_setpairwithstr (
qse_xli_t* xli, qse_xli_t* xli,
const qse_xli_list_t* list, const qse_xli_list_t* list,
@ -749,7 +753,6 @@ QSE_EXPORT qse_size_t qse_xli_countpairs (
const qse_char_t* fqpn const qse_char_t* fqpn
); );
/** /**
* The qse_xli_addsegtostr() function creates a new string segment made of * The qse_xli_addsegtostr() function creates a new string segment made of
* the character string pointed to by \a value and chains it to the XLI string * the character string pointed to by \a value and chains it to the XLI string

View File

@ -891,49 +891,43 @@ qse_xli_pair_t* qse_xli_setpairwithstr (qse_xli_t* xli, const qse_xli_list_t* li
qse_xli_pair_t* pair, * xpair; qse_xli_pair_t* pair, * xpair;
pair = qse_xli_findpair (xli, list, fqpn); pair = qse_xli_findpair (xli, list, fqpn);
if (pair) if (!pair) return QSE_NULL;
if (xli->opt.trait & QSE_XLI_VALIDATE)
{ {
if (xli->opt.trait & QSE_XLI_VALIDATE) qse_rbt_pair_t* scm_pair;
const qse_xli_scm_t* scm;
scm_pair = qse_rbt_search (xli->schema, fqpn, qse_strlen(fqpn));
if (!scm_pair)
{ {
qse_rbt_pair_t* scm_pair; qse_cstr_t key;
const qse_xli_scm_t* scm;
scm_pair = qse_rbt_search (xli->schema, fqpn, qse_strlen(fqpn)); key.ptr = (qse_char_t*)fqpn;
if (!scm_pair) key.len = qse_strlen(fqpn);
{
qse_cstr_t key;
key.ptr = (qse_char_t*)fqpn; qse_xli_seterror (xli, QSE_XLI_EUDKEY, &key, QSE_NULL);
key.len = qse_strlen(fqpn); return QSE_NULL;
qse_xli_seterror (xli, QSE_XLI_EUDKEY, &key, QSE_NULL);
return QSE_NULL;
}
scm = (qse_xli_scm_t*)QSE_RBT_VPTR(scm_pair);
if (scm && !(scm->flags & QSE_XLI_SCM_VALSTR))
{
/* check the value type */
qse_cstr_t key;
key.ptr = (qse_char_t*)fqpn;
key.len = qse_strlen(fqpn);
qse_xli_seterror (xli, QSE_XLI_EILVAL, (const qse_cstr_t*)&key, QSE_NULL);
return QSE_NULL;
}
} }
xpair = qse_xli_insertpairwithstr (xli, pair->super, (qse_xli_atom_t*)pair, pair->key, pair->alias, pair->tag, value, strtag); scm = (qse_xli_scm_t*)QSE_RBT_VPTR(scm_pair);
if (xpair) qse_xli_deletepair (xli, pair);
return xpair; if (scm && !(scm->flags & QSE_XLI_SCM_VALSTR))
} {
else /* check the value type */
{ qse_cstr_t key;
/* TODO: insert a new pair */
return QSE_NULL; key.ptr = (qse_char_t*)fqpn;
key.len = qse_strlen(fqpn);
qse_xli_seterror (xli, QSE_XLI_EILVAL, (const qse_cstr_t*)&key, QSE_NULL);
return QSE_NULL;
}
} }
xpair = qse_xli_insertpairwithstr (xli, pair->super, (qse_xli_atom_t*)pair, pair->key, pair->alias, pair->tag, value, strtag);
if (xpair) qse_xli_deletepair (xli, pair);
return xpair;
} }
qse_size_t qse_xli_countpairs (qse_xli_t* xli, const qse_xli_list_t* list, const qse_char_t* fqpn) qse_size_t qse_xli_countpairs (qse_xli_t* xli, const qse_xli_list_t* list, const qse_char_t* fqpn)