libft
Loading...
Searching...
No Matches
Functions
ft_split_charset.c File Reference

Splits a string into substrings based on a set of delimiters. More...

#include "libft.h"
+ Include dependency graph for ft_split_charset.c:

Functions

static int ft_fill_array_charset (char **array, char *s, char *charset, size_t field_count)
 Fills an array of substrings from the input string.
 
static int ft_is_charset (char c, const char *charset)
 Checks if a character belongs to a charset.
 
char ** ft_split_charset (char *s, char *charset)
 Splits a string into substrings based on a character set.
 
static size_t ft_w_count_charset (char *str, char *charset)
 Counts the number of substrings in a split.
 

Detailed Description

Splits a string into substrings based on a set of delimiters.

Author
Toonsa
Date
2025/02/08

This file provides the implementation of ft_split_charset, a string utility that splits a C string into substrings using a set of delimiter characters (charset). Each resulting substring is dynamically allocated and returned as part of a NULL-terminated array.

Internal helper functions:

Function Documentation

◆ ft_fill_array_charset()

static int ft_fill_array_charset ( char **  array,
char *  s,
char *  charset,
size_t  field_count 
)
static

Fills an array of substrings from the input string.

Allocates and copies substrings from s into the array using the set of delimiter characters. If allocation fails at any point, previously allocated substrings are freed.

Parameters
arrayThe output array of substrings.
sThe input string to split.
charsetThe set of delimiter characters.
field_countThe number of substrings to extract.
Returns
1 on success, 0 on allocation failure.
See also
ft_substr
ft_free_array

◆ ft_is_charset()

static int ft_is_charset ( char  c,
const char *  charset 
)
static

Checks if a character belongs to a charset.

Iterates through the charset and returns 1 if the character c is found. Otherwise, returns 0.

Parameters
cThe character to check.
charsetThe set of delimiter characters.
Returns
1 if the character is in the charset, 0 otherwise.

◆ ft_w_count_charset()

static size_t ft_w_count_charset ( char *  str,
char *  charset 
)
static

Counts the number of substrings in a split.

Traverses the input string and counts how many substrings would result from a split based on the given charset.

Parameters
strThe input string to split.
charsetThe set of delimiter characters.
Returns
The number of expected substrings.