Example #1
0
/**
 * @internal
 *
 * If required, enlarge the buffer to fit the new size.
 *
 * @param buf the buffer to resize
 * @param size the minimum size of the buffer
 *
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 */
Eina_Bool
_eina_strbuf_common_grow(size_t csize, Eina_Strbuf * buf, size_t size)
{
	if ((size + 1) < buf->size)
		return EINA_TRUE;

	return _eina_strbuf_common_resize(csize, buf, size);
}
Example #2
0
/**
 * @brief Remove a slice of the given string buffer.
 *
 * @param buf The string buffer to remove a slice.
 * @param start The initial (inclusive) slice position to start
 *        removing, in bytes.
 * @param end The final (non-inclusive) slice position to finish
 *        removing, in bytes.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * This function removes a slice of @p buf, starting at @p start
 * (inclusive) and ending at @p end (non-inclusive). Both values are
 * in bytes. It returns #EINA_FALSE on failure, #EINA_TRUE otherwise.
 */
Eina_Bool
eina_strbuf_common_remove(size_t csize,
			  Eina_Strbuf * buf, size_t start, size_t end)
{
	size_t remove_len, tail_len;

	if (end >= buf->len)
		end = buf->len;

	if (end <= start)
		return EINA_TRUE;

	remove_len = end - start;
	if (remove_len == buf->len) {
		free(buf->buf);
		return _eina_strbuf_common_init(csize, buf);
	}

	tail_len = buf->len - end + 1;	/* includes '\0' */
	memmove(buf->buf + (start * csize),
		buf->buf + (end * csize), tail_len * csize);
	buf->len -= remove_len;
	return _eina_strbuf_common_resize(csize, buf, buf->len);
}
Example #3
0
/**
 * @internal
 * @brief Remove a slice of the given string buffer.
 *
 * @param csize the character size
 * @param buf The string buffer to remove a slice.
 * @param start The initial (inclusive) slice position to start
 *        removing, in bytes.
 * @param end The final (non-inclusive) slice position to finish
 *        removing, in bytes.
 * @return #EINA_TRUE on success, #EINA_FALSE on failure.
 *
 * This function removes a slice of @p buf, starting at @p start
 * (inclusive) and ending at @p end (non-inclusive). Both values are
 * in bytes. It returns #EINA_FALSE on failure, #EINA_TRUE otherwise.
 */
Eina_Bool
eina_strbuf_common_remove(size_t csize,
                          Eina_Strbuf *buf,
                          size_t start,
                          size_t end)
{
   size_t remove_len, tail_len;

   if (end >= buf->len) end = buf->len;
   if (end <= start) return EINA_TRUE;

   /* This is a read only buffer which need change to be made */
   if (buf->ro)
     {
        char *dest;

        dest = malloc(buf->size);
        if (!dest) return 0;
        memcpy(dest, buf->buf, buf->len);
        buf->buf = dest;
     }

   remove_len = end - start;
   if (remove_len == buf->len)
     {
        free(buf->buf);
        return _eina_strbuf_common_init(csize, buf);
     }

   tail_len = buf->len - end + 1; /* includes '\0' */
   memmove(((unsigned char *)(buf->buf)) + (start * csize),
           ((unsigned char *)(buf->buf)) + (end * csize),
           tail_len * csize);
   buf->len -= remove_len;
   return _eina_strbuf_common_resize(csize, buf, buf->len);
}