Libft
42 Libft library documentation
Loading...
Searching...
No Matches
ft_strtrim.c
Go to the documentation of this file.
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* ft_strtrim.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: raphalme <raphalme@student.42.fr> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2025/12/29 19:04:00 by raphalme #+# #+# */
9/* Updated: 2026/04/14 10:45:22 by raphalme ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "../includes/libft.h"
14
22char *ft_strtrim(char const *s1, char const *set)
23{
24 size_t start;
25 size_t end;
26
27 if (!s1 || !set)
28 return (NULL);
29 start = 0;
30 while (s1[start] && ft_strchr(set, s1[start]))
31 start++;
32 end = ft_strlen(s1);
33 while (end > start && ft_strchr(set, s1[end - 1]))
34 end--;
35 return (ft_substr(s1, start, end - start));
36}
char * ft_strtrim(char const *s1, char const *set)
Trims leading and trailing characters from a set.
Definition ft_strtrim.c:22
char * ft_substr(char const *s, unsigned int start, size_t len)
Extracts a substring from a string.
Definition ft_substr.c:23
size_t ft_strlen(const char *str)
Returns the length of a null-terminated string.
Definition ft_strlen.c:21
char * ft_strchr(const char *s, int c)
Finds the first occurrence of a character in a string.
Definition ft_strchr.c:24