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);
+
+/**
* @}
*/
#include <stdio.h>
#include <string.h>
+#include <ctype.h>
#ifdef HAVE_EVIL
# include <Evil.h>
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"