1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Expose JSON internal function to escape string

This commit is contained in:
Jakub Zelenka
2023-04-10 14:13:34 +01:00
parent 102953735c
commit e8a836eb39
4 changed files with 20 additions and 5 deletions

View File

@@ -142,6 +142,21 @@ static PHP_MINFO_FUNCTION(json)
}
/* }}} */
PHP_JSON_API zend_string *php_json_encode_string(const char *s, size_t len, int options)
{
smart_str buf = {0};
php_json_encoder encoder;
php_json_encode_init(&encoder);
if (php_json_escape_string(&buf, s, len, options, &encoder) == FAILURE) {
smart_str_free(&buf);
return NULL;
}
return smart_str_extract(&buf);
}
PHP_JSON_API int php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth) /* {{{ */
{
php_json_encoder encoder;

View File

@@ -31,10 +31,6 @@
static const char digits[] = "0123456789abcdef";
static int php_json_escape_string(
smart_str *buf, const char *s, size_t len,
int options, php_json_encoder *encoder);
static int php_json_determine_array_type(zval *val) /* {{{ */
{
zend_array *myht = Z_ARRVAL_P(val);
@@ -312,7 +308,7 @@ static int php_json_encode_array(smart_str *buf, zval *val, int options, php_jso
}
/* }}} */
static int php_json_escape_string(
int php_json_escape_string(
smart_str *buf, const char *s, size_t len,
int options, php_json_encoder *encoder) /* {{{ */
{

View File

@@ -97,6 +97,8 @@ PHP_JSON_API ZEND_EXTERN_MODULE_GLOBALS(json)
ZEND_TSRMLS_CACHE_EXTERN()
#endif
PHP_JSON_API zend_string *php_json_encode_string(const char *s, size_t len, int options);
PHP_JSON_API int php_json_encode_ex(smart_str *buf, zval *val, int options, zend_long depth);
PHP_JSON_API int php_json_encode(smart_str *buf, zval *val, int options);
PHP_JSON_API int php_json_decode_ex(zval *return_value, const char *str, size_t str_len, zend_long options, zend_long depth);

View File

@@ -35,4 +35,6 @@ static inline void php_json_encode_init(php_json_encoder *encoder)
int php_json_encode_zval(smart_str *buf, zval *val, int options, php_json_encoder *encoder);
int php_json_escape_string(smart_str *buf, const char *s, size_t len, int options, php_json_encoder *encoder);
#endif /* PHP_JSON_ENCODER_H */