forked from enlightenment/efl
eina: add eina_strbuf_trim/rtrim/ltrim()
SVN revision: 64098
This commit is contained in:
parent
93d79aa509
commit
0d53d91b67
|
@ -563,6 +563,33 @@ EAPI Eina_Bool eina_strbuf_replace(Eina_Strbuf *buf, const char *str, const char
|
|||
*/
|
||||
EAPI int eina_strbuf_replace_all(Eina_Strbuf *buf, const char *str, const char *with) EINA_ARG_NONNULL(1, 2, 3);
|
||||
|
||||
/**
|
||||
* @brief Trim the string buffer
|
||||
|
||||
* @param buf the string buffer to work with.
|
||||
*
|
||||
* This function skips whitespaces in the beginning and the end of the buffer.
|
||||
*/
|
||||
EAPI void eina_strbuf_trim(Eina_Strbuf *buf) EINA_ARG_NONNULL(1);
|
||||
|
||||
/**
|
||||
* @brief Left trim the string buffer
|
||||
|
||||
* @param buf the string buffer to work with.
|
||||
*
|
||||
* This function skips whitespaces in the beginning of the buffer.
|
||||
*/
|
||||
EAPI void eina_strbuf_ltrim(Eina_Strbuf *buf) EINA_ARG_NONNULL(1);
|
||||
|
||||
/**
|
||||
* @brief Right trim the string buffer
|
||||
|
||||
* @param buf the string buffer to work with.
|
||||
*
|
||||
* This function skips whitespaces in the end of the buffer.
|
||||
*/
|
||||
EAPI void eina_strbuf_rtrim(Eina_Strbuf *buf) EINA_ARG_NONNULL(1);
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef HAVE_EVIL
|
||||
# include <Evil.h>
|
||||
|
@ -158,6 +159,44 @@ eina_strbuf_insert_vprintf(Eina_Strbuf *buf,
|
|||
return ret;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
eina_strbuf_trim(Eina_Strbuf *buf)
|
||||
{
|
||||
char *c = buf->buf;
|
||||
|
||||
while (buf->len > 0 && isspace(((unsigned char*)(buf->buf))[buf->len - 1]))
|
||||
buf->len--;
|
||||
while (buf->len > 0 && isspace(*c))
|
||||
{
|
||||
c++;
|
||||
buf->len--;
|
||||
}
|
||||
memmove(buf->buf, c, buf->len);
|
||||
((unsigned char *)buf->buf)[buf->len] = '\0';
|
||||
}
|
||||
|
||||
EAPI void
|
||||
eina_strbuf_ltrim(Eina_Strbuf *buf)
|
||||
{
|
||||
char *c = buf->buf;
|
||||
|
||||
while (buf->len > 0 && isspace(*c))
|
||||
{
|
||||
c++;
|
||||
buf->len--;
|
||||
}
|
||||
memmove(buf->buf, c, buf->len);
|
||||
((unsigned char *)buf->buf)[buf->len] = '\0';
|
||||
}
|
||||
|
||||
EAPI void
|
||||
eina_strbuf_rtrim(Eina_Strbuf *buf)
|
||||
{
|
||||
while (buf->len > 0 && isspace(((unsigned char*)(buf->buf))[buf->len - 1]))
|
||||
buf->len--;
|
||||
((unsigned char *)buf->buf)[buf->len] = '\0';
|
||||
}
|
||||
|
||||
/* Unicode */
|
||||
|
||||
#include "eina_strbuf_template_c.x"
|
||||
|
|
Loading…
Reference in New Issue