diff options
author | Nikita Popov <nikic@php.net> | 2016-12-18 22:53:25 +0100 |
---|---|---|
committer | Nikita Popov <nikic@php.net> | 2017-01-01 21:28:21 +0100 |
commit | f3f594a47d63e993595ad344614cee4a910305b1 (patch) | |
tree | 3c63c405034e4bc1523a55f30e9cad8addeab532 /Zend/zend_smart_str.h | |
parent | 384e959a3a19afd898e2c4c4c6431aa273601057 (diff) | |
download | php-git-f3f594a47d63e993595ad344614cee4a910305b1.tar.gz |
Switch reflection to use smart_str
Instead of yet-another-smart-string-implementation.
Expand the smart_str API by:
* smart_str_extract() which gets a finalized zend_string* from a
smart_str, including insertion of the zero byte and handling of
the empty string case. This should be preferred over using
smart_str_0() in conjunction with str.s.
* smart_str_get_len() which gets the length of the smart_str with
handling of the empty string case.
Diffstat (limited to 'Zend/zend_smart_str.h')
-rw-r--r-- | Zend/zend_smart_str.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Zend/zend_smart_str.h b/Zend/zend_smart_str.h index 505b6f3b04..0d61b56a67 100644 --- a/Zend/zend_smart_str.h +++ b/Zend/zend_smart_str.h @@ -20,6 +20,7 @@ #define ZEND_SMART_STR_H #include <zend.h> +#include "zend_globals.h" #include "zend_smart_str_public.h" #define smart_str_appends_ex(dest, src, what) \ @@ -82,6 +83,22 @@ static zend_always_inline void smart_str_0(smart_str *str) { } } +static zend_always_inline size_t smart_str_get_len(smart_str *str) { + return str->s ? ZSTR_LEN(str->s) : 0; +} + +static zend_always_inline zend_string *smart_str_extract(smart_str *str) { + if (str->s) { + zend_string *res; + smart_str_0(str); + res = str->s; + str->s = NULL; + return res; + } else { + return ZSTR_EMPTY_ALLOC(); + } +} + static zend_always_inline void smart_str_appendc_ex(smart_str *dest, char ch, zend_bool persistent) { size_t new_len = smart_str_alloc(dest, 1, persistent); ZSTR_VAL(dest->s)[new_len - 1] = ch; |