]> git.mdlowis.com Git - projs/libcds.git/commitdiff
Implemented substr
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 20 Aug 2014 12:40:06 +0000 (08:40 -0400)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 20 Aug 2014 12:40:06 +0000 (08:40 -0400)
source/string/str.c

index e915b4825b999de0a495732e482d48b45e210111..0f4bdc83fa5def209dff0295eec420bd901d54af 100644 (file)
@@ -110,10 +110,14 @@ str_t* str_erase(str_t* p_str, size_t start, size_t end)
 
 str_t* str_substr(str_t* p_str, size_t start, size_t end)
 {
-    (void)p_str;
-    (void)start;
-    (void)end;
-    return NULL;
+    str_t* p_newstr = NULL;
+    assert(NULL != p_str);
+    assert(start <= end);
+    p_newstr = (str_t*)mem_allocate(sizeof(str_t) + (end - start) + 1, NULL);
+    p_newstr->size = (end-start);
+    memcpy(p_newstr->data, &(p_str->data[start]), end - start);
+    p_newstr->data[p_newstr->size] = '\0';
+    return p_newstr;
 }
 
 int str_compare(str_t* p_str1, str_t* p_str2)