|
libft
|
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. | |
Splits a string into substrings based on a set of delimiters.
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:
ft_is_charset: checks if a character belongs to a charset.ft_w_count_charset: counts how many substrings will be created.ft_fill_array_charset: populates the output array with substrings.
|
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.
| array | The output array of substrings. |
| s | The input string to split. |
| charset | The set of delimiter characters. |
| field_count | The number of substrings to extract. |
|
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.
| c | The character to check. |
| charset | The set of delimiter characters. |
|
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.
| str | The input string to split. |
| charset | The set of delimiter characters. |