cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=95117bc515cba19662ab8bec51406805ad46f970

commit 95117bc515cba19662ab8bec51406805ad46f970
Author: Srivardhan Hebbar <sri.heb...@samsung.com>
Date:   Tue Nov 10 15:04:17 2015 -0800

    eina: Added API to get substring from Eina_Strbuf.
    
    Summary:
    This API is analogous to c++ substr. It returns a Eina_Strbuf with
    substring of passed buf.
    
    Signed-off-by: Srivardhan Hebbar <sri.heb...@samsung.com>
    
    Reviewers: cedric
    
    Reviewed By: cedric
    
    Differential Revision: https://phab.enlightenment.org/D3224
---
 src/lib/eina/eina_strbuf.c | 15 +++++++++++++++
 src/lib/eina/eina_strbuf.h | 14 ++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/src/lib/eina/eina_strbuf.c b/src/lib/eina/eina_strbuf.c
index ff461a7..1470805 100644
--- a/src/lib/eina/eina_strbuf.c
+++ b/src/lib/eina/eina_strbuf.c
@@ -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"
diff --git a/src/lib/eina/eina_strbuf.h b/src/lib/eina/eina_strbuf.h
index 3799a3d..ca45e3e 100644
--- a/src/lib/eina/eina_strbuf.h
+++ b/src/lib/eina/eina_strbuf.h
@@ -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;
+
+/**
  * @}
  */
 

-- 


Reply via email to