예제 #1
0
파일: u_string.cpp 프로젝트: q66/neothyne
void string::reserve(size_t capacity) {
    if (m_first + capacity + 1 <= m_capacity)
        return;

    const size_t size = m_last - m_first;

    char *newfirst = STR_REALLOC(m_first, capacity + 1);
    m_first = newfirst;
    m_last = newfirst + size;
    m_capacity = m_first + capacity;
}
예제 #2
0
void string::reserve(size_t capacity) {
    if (m_first + capacity + 1 <= m_capacity)
        return;

    const size_t size = m_last - m_first;

    char *newfirst = nullptr;
    if (m_first == m_buffer) {
        newfirst = STR_MALLOC(capacity + 1);
        memcpy(newfirst, m_first, size + 1);
    } else {
        newfirst = STR_REALLOC(m_first, capacity + 1);
    }

    m_first = newfirst;
    m_last = newfirst + size;
    m_capacity = m_first + capacity;
}
예제 #3
0
				*d++ = '=';
				*d++ = hex[c >> 4];
				*d++ = hex[c & 0xf];
			} else {
				if ((++lp) > PHP_QPRINT_MAXL) {
					*d++ = '=';
					*d++ = '\015';
					*d++ = '\012';
					lp = 1;
				}
				*d++ = c;
			}
		}
	}
	*d = '\0';
	ret = STR_REALLOC(ret, d - (unsigned char*)ret->val, 0);
	return ret;
}
/* }}} */

/*
*
* Decoding  Quoted-printable string.
*
*/
/* {{{ proto string quoted_printable_decode(string str)
   Convert a quoted-printable string to an 8 bit string */
PHP_FUNCTION(quoted_printable_decode)
{
	char *arg1, *str_in;
	zend_string *str_out;
예제 #4
0
파일: adapter.c 프로젝트: 9466/cphalcon
/**
 * Set the background color of an image. This is only useful for images
 * with alpha transparency.
 *
 * @param string $color hexadecimal color value
 * @param int $opacity background opacity: 0-100
 * @return Phalcon\Image\Adapter
 */
PHP_METHOD(Phalcon_Image_Adapter, background) {

    zval *color, *opacity = NULL;
    zval *tmp_color = NULL, *r = NULL, *g = NULL, *b = NULL;
    long i;
    char *c;
    zval tmp;

    PHALCON_MM_GROW();

    phalcon_fetch_params(1, 1, 1, &color, &opacity);

    if (Z_TYPE_P(color) != IS_STRING) {
        PHALCON_SEPARATE_PARAM(color);
        convert_to_string(color);
    }

    c = Z_STRVAL_P(color);

    if (Z_STRLEN_P(color) > 0 && c[0] == '#') {
        PHALCON_INIT_NVAR(tmp_color);
        phalcon_substr(tmp_color, color, 1, 0);
    } else {
        PHALCON_CPY_WRT_CTOR(tmp_color, color);
    }

    if (Z_STRLEN_P(tmp_color) == 3) {
        /* Convert RGB to RRGGBB */
        c = Z_STRVAL_P(tmp_color);
        if (!IS_INTERNED(c)) {
            STR_REALLOC(c, 7);
        }
        else {
            char* tmp = ecalloc(7, 1);
            memcpy(tmp, c, Z_STRLEN_P(tmp_color));
            c = tmp;
        }

        c[6] = '\0';
        c[5] = c[2];
        c[4] = c[2];
        c[3] = c[1];
        c[2] = c[1];
        c[1] = c[0];
        ZVAL_STRING(tmp_color, c, 0);
    }

    if (Z_STRLEN_P(tmp_color) < 6) {
        PHALCON_THROW_EXCEPTION_STR(phalcon_image_exception_ce, "Color is not valid");
        return;
    }

    INIT_ZVAL(tmp);

    Z_TYPE(tmp) = IS_STRING;
    ZVAL_STRINGL(&tmp, Z_STRVAL_P(tmp_color), 2, 0);

    PHALCON_INIT_NVAR(r);
    _php_math_basetozval(&tmp, 16, r);

    Z_STRVAL(tmp) += 2;
    PHALCON_INIT_NVAR(g);
    _php_math_basetozval(&tmp, 16, g);

    Z_STRVAL(tmp) += 2;
    PHALCON_INIT_NVAR(b);
    _php_math_basetozval(&tmp, 16, b);

    if (!opacity) {
        PHALCON_INIT_NVAR(opacity);
        ZVAL_LONG(opacity, 100);
    } else {
        PHALCON_SEPARATE_PARAM(opacity);

        i = phalcon_get_intval(opacity);

        if (i < 1) {
            PHALCON_INIT_NVAR(opacity);
            ZVAL_LONG(opacity, 1);
        } else if (i > 100) {
            PHALCON_INIT_NVAR(opacity);
            ZVAL_LONG(opacity, 100);
        }
    }

    PHALCON_CALL_METHOD(NULL, this_ptr, "_background", r, g, b, opacity);

    RETURN_THIS();
}
예제 #5
0
파일: adapter.c 프로젝트: 9466/cphalcon
/**
 * Add a text to an image with a specified opacity.
 *
 * @param string text
 * @param int $offset_x offset from the left, If less than 0 offset from the right, If true right the x offset
 * @param int $offset_y offset from the top, If less than 0 offset from the bottom, If true bottom the Y offset
 * @param int $opacity opacity of text: 1-100
 * @param string $color hexadecimal color value
 * @param int $size font pointsize
 * @param string $fontfile font path
 * @return Phalcon\Image\Adapter
 */
PHP_METHOD(Phalcon_Image_Adapter, text) {

    zval **text, **ofs_x = NULL, **ofs_y = NULL, **op = NULL, **fontcolor = NULL, **fontsize = NULL, **fontfile = NULL;
    zval *offset_x = NULL, *offset_y = NULL, *opacity, *color, *size;
    zval *r, *g, *b;
    char *c;
    zval tmp;

    phalcon_fetch_params_ex(1, 6, &text, &ofs_x, &ofs_y, &op, &fontcolor, &fontsize, &fontfile);

    PHALCON_MM_GROW();

    if (!ofs_x || Z_TYPE_PP(ofs_x) == IS_NULL) {
        PHALCON_INIT_VAR(offset_x);
        ZVAL_FALSE(offset_x);
    }
    else {
        PHALCON_CPY_WRT_CTOR(offset_x, *ofs_x);
    }

    if (!ofs_y || Z_TYPE_PP(ofs_y) == IS_NULL) {
        PHALCON_INIT_VAR(offset_y);
        ZVAL_FALSE(offset_y);
    }
    else {
        PHALCON_CPY_WRT_CTOR(offset_y, *ofs_y);
    }

    PHALCON_INIT_VAR(opacity);
    if (!op || Z_TYPE_PP(op) == IS_NULL) {
        ZVAL_LONG(opacity, 100);
    } else {
        PHALCON_ENSURE_IS_LONG(op);
        if (Z_LVAL_PP(op) < 1) {
            ZVAL_LONG(opacity, 1);
        } else if (Z_LVAL_PP(op) > 100) {
            ZVAL_LONG(opacity, 100);
        } else {
            ZVAL_LONG(opacity, Z_LVAL_PP(op));
        }
    }

    PHALCON_INIT_VAR(color);
    if (!fontcolor || Z_TYPE_PP(fontcolor) == IS_NULL) {
        ZVAL_STRING(color, "000000", 1);
    }
    else {
        PHALCON_ENSURE_IS_STRING(fontcolor);
        if (Z_STRLEN_PP(fontcolor) > 1 && Z_STRVAL_PP(fontcolor)[0] == '#') {
            phalcon_substr(color, *fontcolor, 1, 0);
        }
        else {
            ZVAL_STRINGL(color, Z_STRVAL_PP(fontcolor), Z_STRLEN_PP(fontcolor), 1);
        }
    }

    PHALCON_INIT_VAR(size);
    if (!fontsize || Z_TYPE_PP(fontsize) == IS_NULL) {
        ZVAL_LONG(size, 12);
    }
    else {
        PHALCON_ENSURE_IS_LONG(fontsize);
        ZVAL_LONG(size, Z_LVAL_PP(fontsize));
    }

    if (!fontfile) {
        fontfile = &PHALCON_GLOBAL(z_null);
    }

    if (Z_STRLEN_P(color) == 3) {
        /* Convert RGB to RRGGBB */
        c = Z_STRVAL_P(color);
        assert(!IS_INTERNED(c));
        STR_REALLOC(c, 7);
        c[6] = '\0';
        c[5] = c[2];
        c[4] = c[2];
        c[3] = c[1];
        c[2] = c[1];
        c[1] = c[0];
        ZVAL_STRING(color, c, 0);
    }

    if (Z_STRLEN_P(color) < 6) {
        PHALCON_THROW_EXCEPTION_STR(phalcon_image_exception_ce, "color is not valid");
        return;
    }

    INIT_ZVAL(tmp);

    Z_TYPE(tmp) = IS_STRING;
    ZVAL_STRINGL(&tmp, Z_STRVAL_P(color), 2, 0);

    PHALCON_INIT_VAR(r);
    _php_math_basetozval(&tmp, 16, r);

    Z_STRVAL(tmp) += 2;
    PHALCON_INIT_VAR(g);
    _php_math_basetozval(&tmp, 16, g);

    Z_STRVAL(tmp) += 2;
    PHALCON_INIT_VAR(b);
    _php_math_basetozval(&tmp, 16, b);

    PHALCON_CALL_METHOD(NULL, this_ptr, "_text", *text, offset_x, offset_y, opacity, r, g, b, size, *fontfile);

    RETURN_THIS();
}