added the pair_writable callback to xli

This commit is contained in:
hyung-hwan 2018-01-21 17:13:43 +00:00
parent d61c292659
commit b3a288affb
4 changed files with 16 additions and 4 deletions

View File

@ -454,9 +454,15 @@ typedef void (*qse_xli_pair_read_cb_t) (
qse_xli_loc_t* loc qse_xli_loc_t* loc
); );
typedef int (*qse_xli_pair_writable_cb_t) (
qse_xli_t* xli,
qse_xli_pair_t* pair
);
struct qse_xli_cbs_t struct qse_xli_cbs_t
{ {
qse_xli_pair_read_cb_t pair_read; qse_xli_pair_read_cb_t pair_read;
qse_xli_pair_writable_cb_t pair_writable;
}; };
typedef struct qse_xli_cbs_t qse_xli_cbs_t; typedef struct qse_xli_cbs_t qse_xli_cbs_t;

View File

@ -54,6 +54,8 @@ static int write_list (qse_xli_t* xli, qse_xli_list_t* list, int depth)
{ {
qse_xli_pair_t* pair = (qse_xli_pair_t*)curatom; qse_xli_pair_t* pair = (qse_xli_pair_t*)curatom;
if (xli->opt.cbs.pair_writable && !xli->opt.cbs.pair_writable(xli, pair)) continue;
if (pair->tag) if (pair->tag)
{ {
/* the tag can't be written. so ignore it */ /* the tag can't be written. so ignore it */

View File

@ -106,6 +106,8 @@ static int write_list (qse_xli_t* xli, qse_xli_list_t* list, int depth)
{ {
qse_xli_pair_t* pair = (qse_xli_pair_t*)curatom; qse_xli_pair_t* pair = (qse_xli_pair_t*)curatom;
if (xli->opt.cbs.pair_writable && !xli->opt.cbs.pair_writable(xli, pair)) continue;
if (write_indentation(xli, depth) <= -1) return -1; if (write_indentation(xli, depth) <= -1) return -1;
if (!(list->flags & QSE_XLI_LIST_ARRAYED)) if (!(list->flags & QSE_XLI_LIST_ARRAYED))
@ -130,15 +132,15 @@ static int write_list (qse_xli_t* xli, qse_xli_list_t* list, int depth)
switch (pair->val->type) switch (pair->val->type)
{ {
case QSE_XLI_NIL: case QSE_XLI_NIL:
if (write_to_current_stream(xli, QSE_T("nil"), 5, 0) <= -1) return -1; if (write_to_current_stream(xli, QSE_T("nil"), 3, 0) <= -1) return -1;
break; break;
case QSE_XLI_TRUE: case QSE_XLI_TRUE:
if (write_to_current_stream(xli, QSE_T("true"), 6, 0) <= -1) return -1; if (write_to_current_stream(xli, QSE_T("true"), 4, 0) <= -1) return -1;
break; break;
case QSE_XLI_FALSE: case QSE_XLI_FALSE:
if (write_to_current_stream(xli, QSE_T("false"), 7, 0) <= -1) return -1; if (write_to_current_stream(xli, QSE_T("false"), 5, 0) <= -1) return -1;
break; break;
case QSE_XLI_STR: case QSE_XLI_STR:

View File

@ -268,6 +268,8 @@ static int write_list (qse_xli_t* xli, qse_xli_list_t* list, int depth)
{ {
qse_xli_pair_t* pair = (qse_xli_pair_t*)curatom; qse_xli_pair_t* pair = (qse_xli_pair_t*)curatom;
if (xli->opt.cbs.pair_writable && !xli->opt.cbs.pair_writable(xli, pair)) continue;
if (write_indentation (xli, depth) <= -1) return -1; if (write_indentation (xli, depth) <= -1) return -1;
if (pair->tag) if (pair->tag)