From 435ab65d59f2a2eb1908a4b399049f6bfa0934e3 Mon Sep 17 00:00:00 2001 From: Tucker Evans Date: Thu, 31 Dec 2020 03:20:14 -0500 Subject: Add func to embed a char* (str) into a rope --- structures/rope/rope.c | 16 ++++++++++++++++ structures/rope/rope.h | 1 + 2 files changed, 17 insertions(+) diff --git a/structures/rope/rope.c b/structures/rope/rope.c index 9e0d551..e1ae4a9 100644 --- a/structures/rope/rope.c +++ b/structures/rope/rope.c @@ -27,3 +27,19 @@ rope* rope_new() return tmp; } + +rope* str_to_rope(str) +char *str; +{ + rope *tmp; + + if (!str) + return NULL; + + tmp = rope_new(); + tmp->len = strlen(str); + tmp->str = strdup(str); + + return tmp; +} + diff --git a/structures/rope/rope.h b/structures/rope/rope.h index 4ffd726..80e60a3 100644 --- a/structures/rope/rope.h +++ b/structures/rope/rope.h @@ -4,5 +4,6 @@ typede struct rope_s rope; rope* rope_new(); +rope* str_to_rope(char*); #endif -- cgit v1.1