2000-09-27 15:26:39 +00:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2014-09-19 16:33:14 +00:00
|
|
|
| PHP Version 7 |
|
2000-09-27 15:26:39 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2015-01-15 15:27:30 +00:00
|
|
|
| Copyright (c) 1997-2015 The PHP Group |
|
2000-09-27 15:26:39 +00:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 12:51:34 +00:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2000-09-27 15:26:39 +00:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-10 20:04:29 +00:00
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 12:51:34 +00:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
2000-09-27 15:26:39 +00:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
2002-02-28 08:29:35 +00:00
|
|
|
| Author: Sascha Schumann <sascha@schumann.cx> |
|
2000-09-27 15:26:39 +00:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
2014-09-20 20:42:02 +00:00
|
|
|
#ifndef ZEND_SMART_STR_H
|
|
|
|
#define ZEND_SMART_STR_H
|
2005-01-10 15:20:53 +00:00
|
|
|
|
2001-02-16 18:55:58 +00:00
|
|
|
#include <zend.h>
|
2014-09-20 20:42:02 +00:00
|
|
|
#include "zend_smart_str_public.h"
|
2001-02-16 18:55:58 +00:00
|
|
|
|
2001-07-11 23:13:55 +00:00
|
|
|
#ifndef SMART_STR_PREALLOC
|
2006-05-03 13:32:10 +00:00
|
|
|
#define SMART_STR_PREALLOC 128
|
2001-07-11 23:13:55 +00:00
|
|
|
#endif
|
|
|
|
|
2003-06-18 16:15:47 +00:00
|
|
|
#ifndef SMART_STR_START_SIZE
|
2006-05-03 13:32:10 +00:00
|
|
|
#define SMART_STR_START_SIZE 78
|
2003-06-18 16:15:47 +00:00
|
|
|
#endif
|
|
|
|
|
2003-03-16 23:02:19 +00:00
|
|
|
#define smart_str_appends_ex(dest, src, what) \
|
|
|
|
smart_str_appendl_ex((dest), (src), strlen(src), (what))
|
|
|
|
#define smart_str_appends(dest, src) \
|
|
|
|
smart_str_appendl((dest), (src), strlen(src))
|
|
|
|
#define smart_str_appendc(dest, c) \
|
|
|
|
smart_str_appendc_ex((dest), (c), 0)
|
|
|
|
#define smart_str_appendl(dest, src, len) \
|
|
|
|
smart_str_appendl_ex((dest), (src), (len), 0)
|
2014-09-21 18:47:07 +00:00
|
|
|
#define smart_str_append(dest, src) \
|
|
|
|
smart_str_append_ex((dest), (src), 0)
|
2014-09-21 18:28:44 +00:00
|
|
|
#define smart_str_append_smart_str(dest, src) \
|
|
|
|
smart_str_append_smart_str_ex((dest), (src), 0)
|
2014-09-19 20:16:01 +00:00
|
|
|
#define smart_str_sets(dest, src) \
|
|
|
|
smart_str_setl((dest), (src), strlen(src));
|
2014-08-25 17:24:55 +00:00
|
|
|
#define smart_str_append_long(dest, val) \
|
|
|
|
smart_str_append_long_ex((dest), (val), 0)
|
2003-03-16 23:02:19 +00:00
|
|
|
#define smart_str_append_unsigned(dest, val) \
|
|
|
|
smart_str_append_unsigned_ex((dest), (val), 0)
|
|
|
|
|
2014-09-19 20:16:01 +00:00
|
|
|
static zend_always_inline size_t smart_str_alloc(smart_str *str, size_t len, zend_bool persistent) {
|
|
|
|
size_t newlen;
|
|
|
|
if (!str->s) {
|
|
|
|
newlen = len;
|
|
|
|
str->a = newlen < SMART_STR_START_SIZE
|
|
|
|
? SMART_STR_START_SIZE
|
|
|
|
: newlen + SMART_STR_PREALLOC;
|
|
|
|
str->s = zend_string_alloc(str->a, persistent);
|
|
|
|
str->s->len = 0;
|
|
|
|
} else {
|
|
|
|
newlen = str->s->len + len;
|
|
|
|
if (newlen >= str->a) {
|
|
|
|
str->a = newlen + SMART_STR_PREALLOC;
|
2014-09-19 21:54:58 +00:00
|
|
|
str->s = (zend_string *) perealloc(str->s, _STR_HEADER_SIZE + str->a + 1, persistent);
|
2014-09-19 20:16:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return newlen;
|
|
|
|
}
|
2003-03-16 23:02:19 +00:00
|
|
|
|
2014-09-19 20:16:01 +00:00
|
|
|
static zend_always_inline void smart_str_free(smart_str *str) {
|
|
|
|
if (str->s) {
|
|
|
|
zend_string_release(str->s);
|
|
|
|
str->s = NULL;
|
|
|
|
}
|
|
|
|
str->a = 0;
|
|
|
|
}
|
2003-03-16 23:02:19 +00:00
|
|
|
|
2014-09-19 20:16:01 +00:00
|
|
|
static zend_always_inline void smart_str_0(smart_str *str) {
|
|
|
|
if (str->s) {
|
|
|
|
str->s->val[str->s->len] = '\0';
|
|
|
|
}
|
|
|
|
}
|
2003-03-16 23:02:19 +00:00
|
|
|
|
2014-09-19 20:16:01 +00:00
|
|
|
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);
|
|
|
|
dest->s->val[new_len - 1] = ch;
|
|
|
|
dest->s->len = new_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static zend_always_inline void smart_str_appendl_ex(smart_str *dest, const char *str, size_t len, zend_bool persistent) {
|
|
|
|
size_t new_len = smart_str_alloc(dest, len, persistent);
|
|
|
|
memcpy(dest->s->val + dest->s->len, str, len);
|
|
|
|
dest->s->len = new_len;
|
|
|
|
}
|
|
|
|
|
2014-09-21 18:47:07 +00:00
|
|
|
static zend_always_inline void smart_str_append_ex(smart_str *dest, const zend_string *src, zend_bool persistent) {
|
|
|
|
smart_str_appendl_ex(dest, src->val, src->len, persistent);
|
|
|
|
}
|
|
|
|
|
2014-09-21 18:28:44 +00:00
|
|
|
static zend_always_inline void smart_str_append_smart_str_ex(smart_str *dest, const smart_str *src, zend_bool persistent) {
|
2014-09-19 20:16:01 +00:00
|
|
|
if (src->s && src->s->len) {
|
2014-09-21 18:47:07 +00:00
|
|
|
smart_str_append_ex(dest, src->s, persistent);
|
2014-09-19 20:16:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-19 21:22:26 +00:00
|
|
|
static zend_always_inline void smart_str_append_long_ex(smart_str *dest, zend_long num, zend_bool persistent) {
|
|
|
|
char buf[32];
|
|
|
|
char *result = zend_print_long_to_buf(buf + sizeof(buf) - 1, num);
|
|
|
|
smart_str_appendl_ex(dest, result, buf + sizeof(buf) - 1 - result, persistent);
|
2000-09-27 15:26:39 +00:00
|
|
|
}
|
|
|
|
|
2014-09-19 21:22:26 +00:00
|
|
|
static zend_always_inline void smart_str_append_unsigned_ex(smart_str *dest, zend_ulong num, zend_bool persistent) {
|
|
|
|
char buf[32];
|
|
|
|
char *result = zend_print_ulong_to_buf(buf + sizeof(buf) - 1, num);
|
|
|
|
smart_str_appendl_ex(dest, result, buf + sizeof(buf) - 1 - result, persistent);
|
2000-10-26 18:01:51 +00:00
|
|
|
}
|
2000-09-27 15:26:39 +00:00
|
|
|
|
2014-09-19 21:22:26 +00:00
|
|
|
static zend_always_inline void smart_str_setl(smart_str *dest, const char *src, size_t len) {
|
|
|
|
smart_str_free(dest);
|
|
|
|
smart_str_appendl(dest, src, len);
|
|
|
|
}
|
2002-04-21 01:17:49 +00:00
|
|
|
|
2000-09-27 15:26:39 +00:00
|
|
|
#endif
|
2014-09-20 20:42:02 +00:00
|
|
|
|