Exemple #1
0
// perform re-allocation to remove wasted space.
void String::trim(void)
{
    size_type min_size = d_cplength + 1;

    // only re-allocate when not using quick-buffer, and when size can be trimmed
    if ((d_reserve > CEGUI_STR_QUICKBUFF_SIZE) && (d_reserve > min_size))
    {
            // see if we can trim to quick-buffer
        if (min_size <= CEGUI_STR_QUICKBUFF_SIZE)
        {
            memcpy(d_quickbuff, d_buffer, min_size * sizeof(utf32));
            CEGUI_DELETE_ARRAY_PT(d_buffer, utf32, d_reserve, String);
            d_reserve = CEGUI_STR_QUICKBUFF_SIZE;
        }
        // re-allocate buffer
        else
        {
            utf32* temp = CEGUI_NEW_ARRAY_PT(utf32, min_size, String);
            memcpy(temp, d_buffer, min_size * sizeof(utf32));
            CEGUI_DELETE_ARRAY_PT(d_buffer, utf32, d_reserve, String);
            d_buffer = temp;
            d_reserve = min_size;
        }

    }

}
Exemple #2
0
bool String::grow(size_type new_size)
{
    // check for too big
    if (max_size() <= new_size)
        CEGUI_THROW(
            std::length_error("Resulting CEGUI::String would be too big"));

    // increase, as we always null-terminate the buffer.
    ++new_size;

    if (new_size > d_reserve)
    {
        utf32* temp = CEGUI_NEW_ARRAY_PT(utf32, new_size, String);

        if (d_reserve > CEGUI_STR_QUICKBUFF_SIZE)
        {
            memcpy(temp, d_buffer, (d_cplength + 1) * sizeof(utf32));
            CEGUI_DELETE_ARRAY_PT(d_buffer, utf32, d_reserve, String);
        }
        else
        {
            memcpy(temp, d_quickbuff, (d_cplength + 1) * sizeof(utf32));
        }

        d_buffer = temp;
        d_reserve = new_size;

        return true;
    }

    return false;
}
Exemple #3
0
//----------------------------------------------------------------------------//
void Font::setMaxCodepoint(utf32 codepoint)
{
    if (d_glyphPageLoaded)
    {
        const uint old_size = (((d_maxCodepoint + GLYPHS_PER_PAGE) / GLYPHS_PER_PAGE)
            + BITS_PER_UINT - 1) / BITS_PER_UINT;

        CEGUI_DELETE_ARRAY_PT(d_glyphPageLoaded, uint, old_size, Font);
    }

    d_maxCodepoint = codepoint;

    const uint npages = (codepoint + GLYPHS_PER_PAGE) / GLYPHS_PER_PAGE;
    const uint size = (npages + BITS_PER_UINT - 1) / BITS_PER_UINT;

    d_glyphPageLoaded = CEGUI_NEW_ARRAY_PT(uint, size, Font);
    memset(d_glyphPageLoaded, 0, size * sizeof(uint));
}
Exemple #4
0
// build an internal buffer with the string encoded as utf8 (remains valid until string is modified).
utf8* String::build_utf8_buff(void) const
{
    size_type buffsize = encoded_size(ptr(), d_cplength) + 1;

    if (buffsize > d_encodedbufflen) {

        if (d_encodedbufflen > 0)
        {
            CEGUI_DELETE_ARRAY_PT(d_encodedbuff, utf8, d_encodedbufflen, String);
        }

        d_encodedbuff = CEGUI_NEW_ARRAY_PT(utf8, buffsize, String);
        d_encodedbufflen = buffsize;
    }

    encode(ptr(), d_encodedbuff, buffsize, d_cplength);

    // always add a null at end
    d_encodedbuff[buffsize-1] = ((utf8)0);
    d_encodeddatlen = buffsize;

    return d_encodedbuff;
}
static T* iconvTranscode(IconvHelper& ich, const char* in_buf, size_t in_len)
{
    std::vector<T CEGUI_VECTOR_ALLOC(T)> out_vec;
    out_vec.resize(in_len);
    size_t out_count = 0;

    while (true)
    {
        char* out_buf =
            reinterpret_cast<char*>(&out_vec[out_count]);
        const size_t start_out_bytes_left =
            (out_vec.size() - out_count) * sizeof(T);
        size_t out_bytes_left = start_out_bytes_left;

        const size_t result = ich.iconv(&in_buf, &in_len,
                                        &out_buf, &out_bytes_left);

        out_count +=
            (start_out_bytes_left - out_bytes_left) / sizeof(T);

        if (result != static_cast<size_t>(-1))
        {
            T* ret_buff = CEGUI_NEW_ARRAY_PT(T, out_count + 1,
                                             CEGUI::BufferAllocator);
            memcpy(ret_buff, &out_vec[0], out_count * sizeof(T));
            ret_buff[out_count] = 0;
            return ret_buff;
        }

        if (errno != E2BIG)
            break;

        out_vec.resize(out_vec.size() + 8); // this is some arbitrary number
    }

    ich.throwErrorException(errno);
}