summaryrefslogtreecommitdiff
path: root/libft/ft_strtrim.c
diff options
context:
space:
mode:
Diffstat (limited to 'libft/ft_strtrim.c')
-rw-r--r--libft/ft_strtrim.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/libft/ft_strtrim.c b/libft/ft_strtrim.c
new file mode 100644
index 0000000..d844fb4
--- /dev/null
+++ b/libft/ft_strtrim.c
@@ -0,0 +1,33 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_strtrim.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: kdx <kdx @student.42angouleme.fr +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2022/09/28 09:23:36 by kdx #+# #+# */
+/* Updated: 2022/10/14 02:37:46 by kdx ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "libft.h"
+
+char *ft_strtrim(char const *s1, char const *set)
+{
+ size_t begin;
+ size_t to_copy;
+ size_t len;
+
+ if (s1 == NULL || set == NULL)
+ return (NULL);
+ len = ft_strlen(s1);
+ if (len == 0)
+ return (ft_strdup(""));
+ begin = 0;
+ while (ft_strchr(set, s1[begin]) != NULL)
+ begin += 1;
+ to_copy = len - begin;
+ while (ft_strchr(set, s1[begin + to_copy - 1]) != NULL && to_copy)
+ to_copy -= 1;
+ return (ft_substr(s1, begin, to_copy));
+}