Add TextWriter, IOException, per-VM module data and pre-load imports; Add console module with Console class
This commit is contained in:
@@ -3786,87 +3786,6 @@ static int PH7_builtin_sprintf(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
PH7_InputFormat(sprintfConsumer, pCtx, zFormat, nLen, nArg, apArg, 0, FALSE);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* Callback [i.e: Formatted input consumer] of the printf function.
|
||||
*/
|
||||
static int printfConsumer(ph7_context *pCtx, const char *zInput, int nLen, void *pUserData) {
|
||||
ph7_int64 *pCounter = (ph7_int64 *)pUserData;
|
||||
/* Call the VM output consumer directly */
|
||||
ph7_context_output(pCtx, zInput, nLen);
|
||||
/* Increment counter */
|
||||
*pCounter += nLen;
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int64 printf(string $format[,mixed $args[,mixed $... ]])
|
||||
* Output a formatted string.
|
||||
* Parameters
|
||||
* $format
|
||||
* See sprintf() for a description of format.
|
||||
* Return
|
||||
* The length of the outputted string.
|
||||
*/
|
||||
static int PH7_builtin_printf(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_int64 nCounter = 0;
|
||||
const char *zFormat;
|
||||
int nLen;
|
||||
if(nArg < 1 || !ph7_value_is_string(apArg[0])) {
|
||||
/* Missing/Invalid arguments, return 0 */
|
||||
ph7_result_int(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Extract the string format */
|
||||
zFormat = ph7_value_to_string(apArg[0], &nLen);
|
||||
if(nLen < 1) {
|
||||
/* Empty string */
|
||||
ph7_result_int(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Format the string */
|
||||
PH7_InputFormat(printfConsumer, pCtx, zFormat, nLen, nArg, apArg, (void *)&nCounter, FALSE);
|
||||
/* Return the length of the outputted string */
|
||||
ph7_result_int64(pCtx, nCounter);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int vprintf(string $format,array $args)
|
||||
* Output a formatted string.
|
||||
* Parameters
|
||||
* $format
|
||||
* See sprintf() for a description of format.
|
||||
* Return
|
||||
* The length of the outputted string.
|
||||
*/
|
||||
static int PH7_builtin_vprintf(ph7_context *pCtx, int nArg, ph7_value **apArg) {
|
||||
ph7_int64 nCounter = 0;
|
||||
const char *zFormat;
|
||||
ph7_hashmap *pMap;
|
||||
SySet sArg;
|
||||
int nLen, n;
|
||||
if(nArg < 2 || !ph7_value_is_string(apArg[0]) || !ph7_value_is_array(apArg[1])) {
|
||||
/* Missing/Invalid arguments, return 0 */
|
||||
ph7_result_int(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Extract the string format */
|
||||
zFormat = ph7_value_to_string(apArg[0], &nLen);
|
||||
if(nLen < 1) {
|
||||
/* Empty string */
|
||||
ph7_result_int(pCtx, 0);
|
||||
return PH7_OK;
|
||||
}
|
||||
/* Point to the hashmap */
|
||||
pMap = (ph7_hashmap *)apArg[1]->x.pOther;
|
||||
/* Extract arguments from the hashmap */
|
||||
n = PH7_HashmapValuesToSet(pMap, &sArg);
|
||||
/* Format the string */
|
||||
PH7_InputFormat(printfConsumer, pCtx, zFormat, nLen, n, (ph7_value **)SySetBasePtr(&sArg), (void *)&nCounter, TRUE);
|
||||
/* Return the length of the outputted string */
|
||||
ph7_result_int64(pCtx, nCounter);
|
||||
/* Release the container */
|
||||
SySetRelease(&sArg);
|
||||
return PH7_OK;
|
||||
}
|
||||
/*
|
||||
* int vsprintf(string $format,array $args)
|
||||
* Output a formatted string.
|
||||
@@ -7457,8 +7376,6 @@ static const ph7_builtin_func aBuiltInFunc[] = {
|
||||
{ "str_repeat", PH7_builtin_str_repeat },
|
||||
{ "nl2br", PH7_builtin_nl2br },
|
||||
{ "sprintf", PH7_builtin_sprintf },
|
||||
{ "printf", PH7_builtin_printf },
|
||||
{ "vprintf", PH7_builtin_vprintf },
|
||||
{ "vsprintf", PH7_builtin_vsprintf },
|
||||
{ "size_format", PH7_builtin_size_format},
|
||||
{ "md5", PH7_builtin_md5 },
|
||||
|
||||
Reference in New Issue
Block a user