eina: Added API to get substring from Eina_Strbuf.
authorSrivardhan Hebbar <sri.hebbar@samsung.com>
Tue, 10 Nov 2015 23:04:17 +0000 (15:04 -0800)
committerCedric BAIL <cedric@osg.samsung.com>
Tue, 10 Nov 2015 23:04:17 +0000 (15:04 -0800)
Summary:
This API is analogous to c++ substr. It returns a Eina_Strbuf with
substring of passed buf.

Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com>
Reviewers: cedric

Reviewed By: cedric

Differential Revision: https://phab.enlightenment.org/D3224

src/lib/eina/eina_strbuf.c
src/lib/eina/eina_strbuf.h

index ff461a7..1470805 100644 (file)
@@ -205,6 +205,21 @@ eina_strbuf_tolower(Eina_Strbuf *buf)
    eina_str_tolower((char **)&(buf->buf));
 }
 
+EAPI Eina_Strbuf *
+eina_strbuf_substr_get(Eina_Strbuf *buf, size_t pos, size_t len)
+{
+   char *str;
+
+   if ((!buf) || ((pos + len) > buf->len))
+      return NULL;
+
+   str = calloc(0, len + 1);
+
+   strncpy(str,((char *)(buf->buf)) + pos, len);
+
+   return eina_strbuf_manage_new(str);
+}
+
 /* Unicode */
 
 #include "eina_strbuf_template_c.x"
index 3799a3d..ca45e3e 100644 (file)
@@ -651,6 +651,20 @@ EAPI void eina_strbuf_rtrim(Eina_Strbuf *buf) EINA_ARG_NONNULL(1);
 EAPI void eina_strbuf_tolower(Eina_Strbuf *buf) EINA_ARG_NONNULL(1);
 
 /**
+ * @brief Obtain substring from the src.
+ *
+ * @param buf the src string.
+ * @param pos the position in the source string from which the substring
+ *            should be created. The first character is denoted by a
+ *            value of 0 (not 1).
+ * @param len the length from pos that should be copied to substring.
+ *
+ * This function creates a Eina_Strbuf which is a substring of buf which
+ * is passed from pos position with len length.
+ */
+EAPI Eina_Strbuf * eina_strbuf_substr_get(Eina_Strbuf *buf, size_t pos, size_t len) EINA_MALLOC EINA_WARN_UNUSED_RESULT;
+
+/**
  * @}
  */