enhanced qse_awk_rtx_valtostr()

This commit is contained in:
2011-05-25 09:14:58 +00:00
parent 8497ddae25
commit 26427dd4c3
13 changed files with 246 additions and 161 deletions

View File

@ -1,5 +1,5 @@
/*
* $Id: Awk.hpp 477 2011-05-24 04:22:40Z hyunghwan.chung $
* $Id: Awk.hpp 479 2011-05-24 15:14:58Z hyunghwan.chung $
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
@ -454,6 +454,16 @@ public:
this->set (x);
return *this;
}
const char_t* pointer () const
{
return this->ptr;
}
size_t length () const
{
return this->len;
}
};
///

View File

@ -1,5 +1,5 @@
/*
* $Id: awk.h 477 2011-05-24 04:22:40Z hyunghwan.chung $
* $Id: awk.h 479 2011-05-24 15:14:58Z hyunghwan.chung $
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
@ -1059,6 +1059,7 @@ enum qse_awk_val_type_t
* following values:
*
* - #QSE_AWK_RTX_VALTOSTR_CPL
* - #QSE_AWK_RTX_VALTOSTR_CPLCP
* - #QSE_AWK_RTX_VALTOSTR_CPLDUP
* - #QSE_AWK_RTX_VALTOSTR_STRP
* - #QSE_AWK_RTX_VALTOSTR_STRPCAT
@ -1069,12 +1070,14 @@ enum qse_awk_rtx_valtostr_type_t
{
/** use u.cpl of #qse_awk_rtx_valtostr_out_t */
QSE_AWK_RTX_VALTOSTR_CPL = 0x00,
/** use u.cplcp of #qse_awk_rtx_valtostr_out_t */
QSE_AWK_RTX_VALTOSTR_CPLCP = 0x01,
/** use u.cpldup of #qse_awk_rtx_valtostr_out_t */
QSE_AWK_RTX_VALTOSTR_CPLDUP = 0x01,
QSE_AWK_RTX_VALTOSTR_CPLDUP = 0x02,
/** use u.strp of #qse_awk_rtx_valtostr_out_t */
QSE_AWK_RTX_VALTOSTR_STRP = 0x02,
QSE_AWK_RTX_VALTOSTR_STRP = 0x03,
/** use u.strpcat of #qse_awk_rtx_valtostr_out_t */
QSE_AWK_RTX_VALTOSTR_STRPCAT = 0x03,
QSE_AWK_RTX_VALTOSTR_STRPCAT = 0x04,
/** convert for print */
QSE_AWK_RTX_VALTOSTR_PRINT = 0x10
};
@ -1090,6 +1093,7 @@ struct qse_awk_rtx_valtostr_out_t
union
{
qse_xstr_t cpl;
qse_xstr_t cplcp;
qse_xstr_t cpldup; /* need to free cpldup.ptr */
qse_str_t* strp;
qse_str_t* strpcat;
@ -2063,8 +2067,8 @@ void qse_awk_rtx_refdownval_nofree (
* value.
*/
qse_bool_t qse_awk_rtx_valtobool (
qse_awk_rtx_t* rtx, /**< runtime context */
qse_awk_val_t* val /**< value pointer */
qse_awk_rtx_t* rtx, /**< runtime context */
const qse_awk_val_t* val /**< value pointer */
);
/**
@ -2075,6 +2079,7 @@ qse_bool_t qse_awk_rtx_valtobool (
* The type field is one of the following qse_awk_rtx_valtostr_type_t values:
*
* - #QSE_AWK_RTX_VALTOSTR_CPL
* - #QSE_AWK_RTX_VALTOSTR_CPLCP
* - #QSE_AWK_RTX_VALTOSTR_CPLDUP
* - #QSE_AWK_RTX_VALTOSTR_STRP
* - #QSE_AWK_RTX_VALTOSTR_STRPCAT
@ -2086,7 +2091,22 @@ qse_bool_t qse_awk_rtx_valtobool (
* You should initialize or free other fields before and after the call
* depending on the type field as shown below:
*
* If you have a static buffer, use #QSE_AWK_RTX_VALTOSTR_CPL.
* If you have a static buffer, use #QSE_AWK_RTX_VALTOSTR_CPLCP.
* the resulting string is copied to the buffer.
* @code
* qse_awk_rtx_valtostr_out_t out;
* qse_char_t buf[100];
* out.type = QSE_AWK_RTX_VALTOSTR_CPLCP;
* out.u.cplcp.ptr = buf;
* out.u.cplcp.len = QSE_COUNTOF(buf);
* if (qse_awk_rtx_valtostr (rtx, v, &out) == QSE_NULL) goto oops;
* qse_printf (QSE_T("%.*s\n"), (int)out.u.cplcp.len, out.u.cplcp.ptr);
* @endcode
*
* #QSE_AWK_RTX_VALTOSTR_CPL is different from #QSE_AWK_RTX_VALTOSTR_CPLCP
* in that it doesn't copy the string to the buffer if the type of the value
* is #QSE_AWK_VAL_STR. It copies the resulting string to the buffer if
* the value type is not #QSE_AWK_VAL_STR.
* @code
* qse_awk_rtx_valtostr_out_t out;
* qse_char_t buf[100];
@ -2136,7 +2156,7 @@ qse_bool_t qse_awk_rtx_valtobool (
*/
qse_char_t* qse_awk_rtx_valtostr (
qse_awk_rtx_t* rtx, /**< runtime context */
qse_awk_val_t* val, /**< value to convert */
const qse_awk_val_t* val, /**< value to convert */
qse_awk_rtx_valtostr_out_t* out /**< output buffer */
);
@ -2158,9 +2178,9 @@ qse_char_t* qse_awk_rtx_valtostr (
* #QSE_NULL on failure
*/
qse_char_t* qse_awk_rtx_valtocpldup (
qse_awk_rtx_t* rtx, /**< runtime context */
qse_awk_val_t* val, /**< value to convert */
qse_size_t* len /**< result length */
qse_awk_rtx_t* rtx, /**< runtime context */
const qse_awk_val_t* val, /**< value to convert */
qse_size_t* len /**< result length */
);
/**
@ -2187,10 +2207,10 @@ qse_char_t* qse_awk_rtx_valtocpldup (
* a floating-point number.
*/
int qse_awk_rtx_valtonum (
qse_awk_rtx_t* rtx,
qse_awk_val_t* val,
qse_long_t* l,
qse_real_t* r
qse_awk_rtx_t* rtx,
const qse_awk_val_t* val,
qse_long_t* l,
qse_real_t* r
);
/**

View File

@ -1,5 +1,5 @@
/*
* $Id: lda.h 474 2011-05-23 16:52:37Z hyunghwan.chung $
* $Id: lda.h 479 2011-05-24 15:14:58Z hyunghwan.chung $
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
@ -48,17 +48,18 @@ typedef enum qse_lda_walk_t qse_lda_walk_t;
#define QSE_LDA_SIZE(lda) (*(const qse_size_t*)&(lda)->size)
#define QSE_LDA_CAPA(lda) (*(const qse_size_t*)&(lda)->capa)
#define QSE_LDA_DATA(lda,index) ((const qse_xptl_t*)&(lda)->node[index]->val)
#define QSE_LDA_DPTR(lda,index) ((lda)->node[index]->val.ptr)
#define QSE_LDA_DLEN(lda,index) ((lda)->node[index]->val.len)
#define QSE_LDA_SLOT(lda,index) ((lda)->slot[index])
#define QSE_LDA_DPTL(lda,index) ((const qse_xptl_t*)&(lda)->slot[index]->val)
#define QSE_LDA_DPTR(lda,index) ((lda)->slot[index]->val.ptr)
#define QSE_LDA_DLEN(lda,index) ((lda)->slot[index]->val.len)
/**
* The qse_lda_copier_t type defines a callback function for node construction.
* A node is contructed when a user adds data to a list. The user can
* The qse_lda_copier_t type defines a callback function for slot construction.
* A slot is contructed when a user adds data to a list. The user can
* define how the data to add can be maintained in the list. A singly
* linked list not specified with any copiers stores the data pointer and
* the data length into a node. A special copier QSE_LDA_COPIER_INLINE copies
* the contents of the data a user provided into the node. You can use the
* the data length into a slot. A special copier QSE_LDA_COPIER_INLINE copies
* the contents of the data a user provided into the slot. You can use the
* qse_lda_setcopier() function to change the copier.
*
* A copier should return the pointer to the copied data. If it fails to copy
@ -72,7 +73,7 @@ typedef void* (*qse_lda_copier_t) (
);
/**
* The qse_lda_freeer_t type defines a node destruction callback.
* The qse_lda_freeer_t type defines a slot destruction callback.
*/
typedef void (*qse_lda_freeer_t) (
qse_lda_t* lda /**< array */,
@ -120,7 +121,7 @@ typedef qse_size_t (*qse_lda_sizer_t) (
typedef qse_lda_walk_t (*qse_lda_walker_t) (
qse_lda_t* lda /* array */,
qse_size_t index /* index to the visited node */,
qse_size_t index /* index to the visited slot */,
void* ctx /* user-defined context */
);
@ -139,11 +140,11 @@ struct qse_lda_t
qse_byte_t scale; /* scale factor */
qse_size_t size; /* number of items */
qse_size_t capa; /* capacity */
qse_lda_slot_t** node;
qse_lda_slot_t** slot;
};
/**
* The qse_lda_slot_t type defines a linear dynamic array node
* The qse_lda_slot_t type defines a linear dynamic array slot
*/
struct qse_lda_slot_t
{
@ -213,8 +214,8 @@ qse_lda_copier_t qse_lda_getcopier (
/**
* The qse_lda_setcopier() specifies how to clone an element. The special
* copier #QSE_LDA_COPIER_INLINE copies the data inline to the internal node.
* No freeer is invoked when the node is freeed. You may set the copier to
* copier #QSE_LDA_COPIER_INLINE copies the data inline to the internal slot.
* No freeer is invoked when the slot is freeed. You may set the copier to
* #QSE_LDA_COPIER_SIMPLE to perform no special operation when the data
* pointer is stored.
*/
@ -232,7 +233,7 @@ qse_lda_freeer_t qse_lda_getfreeer (
/**
* The qse_lda_setfreeer() function specifies how to destroy an element.
* The @a freeer is called when a node containing the element is destroyed.
* The @a freeer is called when a slot containing the element is destroyed.
*/
void qse_lda_setfreeer (
qse_lda_t* lda /**< lda */,
@ -330,7 +331,7 @@ qse_size_t qse_lda_delete (
);
/**
* The qse_lda_uplete() function deletes data node without compaction.
* The qse_lda_uplete() function deletes data slot without compaction.
* It returns the number of data affected.
*/
qse_size_t qse_lda_uplete (