diff --git a/includes/str.h b/includes/str.h index 84da184..8857667 100644 --- a/includes/str.h +++ b/includes/str.h @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 15:04:59 by rparodi #+# #+# */ -/* Updated: 2025/09/04 11:53:11 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:19:06 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,21 +15,192 @@ # include +/** + * @brief Splits a string into an array of substrings based on a delimiter. + * + * @param s The string to split. + * @param c The delimiter character. + * + * @return A NULL-terminated array of substrings, + * or NULL if memory allocation fails. + */ char **ft_split(char const *s, char c); + +/** + * @brief Locates the first occurrence of a character in a string. + * + * @param s The string to search. + * @param c The character to locate. + * + * @return A pointer to the matched character, + * or NULL if it does not appear in `s`. + */ char *ft_strchr(const char *s, int c); + +/** + * @brief Copies a string. + * + * @param dst The destination buffer. + * @param src The source string. + * + * @return A pointer to `dst`. + */ char *ft_strcpy(char *dst, const char *src); + +/** + * @brief Duplicates a string. + * + * @param s1 The string to duplicate. + * + * @return A pointer to the duplicated string, + * or NULL if memory allocation fails. + */ char *ft_strdup(const char *s); + +/** + * @brief Joins two strings into a new string. + * + * @param s1 The first string. + * @param s2 The second string. + * + * @return A pointer to the new concatenated string, + * or NULL if memory allocation fails. + */ char *ft_strjoin(char const *s1, char const *s2); + +/** + * @brief Applies a function to each character of a string. + * + * @param s The input string. + * @param f The function to apply to each character. + * + * @return A pointer to the newly created string, + * or NULL if memory allocation fails. + */ char *ft_strmapi(char const *s, char (*f)(unsigned int, char)); + +/** + * @brief Copies a string. + * + * @param dst The destination buffer. + * @param src The source string. + * @param size The size to copy + * + * @return A pointer to `dst`. + */ char *ft_strncpy(char *dst, const char *src, size_t size); + +/** + * @brief Locates a substring within a string, up to a specified length. + * + * The `ft_strnstr` function locates the first occurrence of the null-terminated + * string `needle` within the string `haystack`, + * searching only up to `len` characters. + * + * @param big The string to search. + * @param little The substring to locate. + * @param len The maximum number of characters to search. + * + * @return A pointer to the beginning of the located substring, + * or NULL if `needle` is not found. + */ char *ft_strnstr(const char *big, const char *little, size_t len); + +/** + * @brief Locates the last occurrence of a character in a string. + * + * @param s The string to search. + * @param c The character to locate. + * + * @return A pointer to the matched character, + * or NULL if it does not appear in `s`. + */ char *ft_strrchr(const char *s, int c); + +/** + * @brief Trims specified characters from the start and end of a string. + * + * @param s1 The string to trim. + * @param set The set of characters to remove. + * + * @return A pointer to the trimmed string, or NULL if memory allocation fails. + */ char *ft_strtrim(char const *s1, char const *set); + +/** + * @brief Extracts a substring from a string. + * + * @param s The source string. + * @param start The starting index of the substring. + * @param len The maximum length of the substring. + * + * @return A pointer to the substring, or NULL if memory allocation fails. + */ char *ft_substr(char const *s, unsigned int start, size_t len); + +/** + * @brief Compares two strings lexicographically. + * + * @param s1 The first string to compare. + * @param s2 The second string to compare. + * + * @return An integer indicating the relationship between the two strings: + * - `< 0` if `s1` is less than `s2`. + * - `0` if `s1` equals `s2`. + * - `> 0` if `s1` is greater than `s2`. + */ +int ft_strcmp(const char *s1, const char *s2); + +/** + * @brief Compares two strings up to a specified number of characters. + * + * @param s1 The first string to compare. + * @param s2 The second string to compare. + * @param n The maximum number of characters to compare. + * + * @return An integer indicating the relationship between the two strings. + */ int ft_strncmp(const char *s1, const char *s2, size_t n); + +/** + * @brief Appends a string with size limit. + * + * @param dst The destination buffer. + * @param src The source string. + * @param size The size of the destination buffer. + * + * @return The total length of the string it tried to create. + */ size_t ft_strlcat(char *dst, const char *src, size_t size); + +/** + * @brief Copies a string with size limit. + * + * @param dst The destination buffer. + * @param src The source string. + * @param size The maximum number of characters to copy. + * + * @return The total length of `src`. + */ size_t ft_strlcpy(char *dst, const char *src, size_t size); + +/** + * @brief Computes the length of a string. + * + * @param s The input string. + * + * @return The number of characters in the string `s`. + */ size_t ft_strlen(const char *s); + +/** + * @brief Applies a function to each character of a string. + * + * @param s The string to modify. + * @param f The function to apply to each character. + * + * @return void + */ void ft_striteri(char *s, void (*f)(unsigned int, char*)); #endif diff --git a/str/ft_split.c b/str/ft_split.c index ad124d3..04e40d2 100644 --- a/str/ft_split.c +++ b/str/ft_split.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/09 13:56:02 by rparodi #+# #+# */ -/* Updated: 2025/09/01 17:49:19 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -74,15 +74,6 @@ static char **ext_w(char **words_array, const char *str, char sep, int size) return (words_array); } -/** - * @brief Splits a string into an array of substrings based on a delimiter. - * - * @param s The string to split. - * @param c The delimiter character. - * - * @return A NULL-terminated array of substrings, - * or NULL if memory allocation fails. - */ char **ft_split(char const *s, char c) { int size; diff --git a/str/ft_strchr.c b/str/ft_strchr.c index 472841e..432ae21 100644 --- a/str/ft_strchr.c +++ b/str/ft_strchr.c @@ -6,22 +6,13 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/07 16:32:19 by rparodi #+# #+# */ -/* Updated: 2025/09/01 17:49:27 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "str.h" #include -/** - * @brief Locates the first occurrence of a character in a string. - * - * @param s The string to search. - * @param c The character to locate. - * - * @return A pointer to the matched character, - * or NULL if it does not appear in `s`. - */ char *ft_strchr(const char *s, int c) { unsigned int i; diff --git a/str/ft_strcmp.c b/str/ft_strcmp.c index 6ef1976..d382fba 100644 --- a/str/ft_strcmp.c +++ b/str/ft_strcmp.c @@ -6,23 +6,12 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/07 16:56:56 by rparodi #+# #+# */ -/* Updated: 2025/09/01 17:50:06 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:21:46 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include -/** - * @brief Compares two strings lexicographically. - * - * @param s1 The first string to compare. - * @param s2 The second string to compare. - * - * @return An integer indicating the relationship between the two strings: - * - `< 0` if `s1` is less than `s2`. - * - `0` if `s1` equals `s2`. - * - `> 0` if `s1` is greater than `s2`. - */ int ft_strcmp(const char *s1, const char *s2) { size_t i; diff --git a/str/ft_strcpy.c b/str/ft_strcpy.c index 36eae2a..2077e55 100644 --- a/str/ft_strcpy.c +++ b/str/ft_strcpy.c @@ -6,20 +6,12 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 16:14:10 by rparodi #+# #+# */ -/* Updated: 2025/09/01 17:36:18 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include -/** - * @brief Copies a string. - * - * @param dst The destination buffer. - * @param src The source string. - * - * @return A pointer to `dst`. - */ char *ft_strcpy(char *dst, const char *src) { size_t i; diff --git a/str/ft_strdup.c b/str/ft_strdup.c index 0a1a8c6..3f32edd 100644 --- a/str/ft_strdup.c +++ b/str/ft_strdup.c @@ -6,21 +6,13 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/07 16:53:59 by rparodi #+# #+# */ -/* Updated: 2025/09/01 17:58:58 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "str.h" #include -/** - * @brief Duplicates a string. - * - * @param s1 The string to duplicate. - * - * @return A pointer to the duplicated string, - * or NULL if memory allocation fails. - */ char *ft_strdup(const char *s) { size_t len; diff --git a/str/ft_striteri.c b/str/ft_striteri.c index 3a88652..3b844ae 100644 --- a/str/ft_striteri.c +++ b/str/ft_striteri.c @@ -6,20 +6,12 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/09 13:57:34 by rparodi #+# #+# */ -/* Updated: 2025/09/01 17:50:26 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include -/** - * @brief Applies a function to each character of a string. - * - * @param s The string to modify. - * @param f The function to apply to each character. - * - * @return void - */ void ft_striteri(char *s, void (*f)(unsigned int, char*)) { size_t i; diff --git a/str/ft_strjoin.c b/str/ft_strjoin.c index ca95a58..42ce3ca 100644 --- a/str/ft_strjoin.c +++ b/str/ft_strjoin.c @@ -6,22 +6,13 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/09 13:55:15 by rparodi #+# #+# */ -/* Updated: 2025/09/01 17:58:58 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "str.h" #include -/** - * @brief Joins two strings into a new string. - * - * @param s1 The first string. - * @param s2 The second string. - * - * @return A pointer to the new concatenated string, - * or NULL if memory allocation fails. - */ char *ft_strjoin(char const *s1, char const *s2) { size_t i; diff --git a/str/ft_strlcat.c b/str/ft_strlcat.c index f8bbf79..351b81d 100644 --- a/str/ft_strlcat.c +++ b/str/ft_strlcat.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/08 22:28:26 by rparodi #+# #+# */ -/* Updated: 2025/09/01 17:52:29 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,15 +23,6 @@ static size_t ft_strnlen(char *dest, size_t size) return (i); } -/** - * @brief Appends a string with size limit. - * - * @param dst The destination buffer. - * @param src The source string. - * @param size The size of the destination buffer. - * - * @return The total length of the string it tried to create. - */ size_t ft_strlcat(char *dest, const char *src, size_t size) { size_t i; diff --git a/str/ft_strlcpy.c b/str/ft_strlcpy.c index 86bd60a..cffe355 100644 --- a/str/ft_strlcpy.c +++ b/str/ft_strlcpy.c @@ -6,22 +6,13 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/07 16:55:25 by rparodi #+# #+# */ -/* Updated: 2025/09/01 17:52:00 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "str.h" #include -/** - * @brief Copies a string with size limit. - * - * @param dst The destination buffer. - * @param src The source string. - * @param size The maximum number of characters to copy. - * - * @return The total length of `src`. - */ size_t ft_strlcpy(char *dst, const char *src, size_t size) { size_t i; diff --git a/str/ft_strlen.c b/str/ft_strlen.c index a6db9cf..b69f10a 100644 --- a/str/ft_strlen.c +++ b/str/ft_strlen.c @@ -6,19 +6,12 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/07 16:56:24 by rparodi #+# #+# */ -/* Updated: 2025/09/01 18:34:21 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include -/** - * @brief Computes the length of a string. - * - * @param s The input string. - * - * @return The number of characters in the string `s`. - */ size_t ft_strlen(const char *s) { size_t i; diff --git a/str/ft_strmapi.c b/str/ft_strmapi.c index 4a2c463..56ebc3e 100644 --- a/str/ft_strmapi.c +++ b/str/ft_strmapi.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/09 13:56:57 by rparodi #+# #+# */ -/* Updated: 2025/09/01 18:28:51 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,15 +14,6 @@ #include "str.h" #include -/** - * @brief Applies a function to each character of a string. - * - * @param s The input string. - * @param f The function to apply to each character. - * - * @return A pointer to the newly created string, - * or NULL if memory allocation fails. - */ char *ft_strmapi(char const *s, char (*f)(unsigned int, char)) { size_t i; diff --git a/str/ft_strncmp.c b/str/ft_strncmp.c index 78933d5..1caeeae 100644 --- a/str/ft_strncmp.c +++ b/str/ft_strncmp.c @@ -6,21 +6,12 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/07 16:56:56 by rparodi #+# #+# */ -/* Updated: 2025/09/01 17:54:01 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include -/** - * @brief Compares two strings up to a specified number of characters. - * - * @param s1 The first string to compare. - * @param s2 The second string to compare. - * @param n The maximum number of characters to compare. - * - * @return An integer indicating the relationship between the two strings. - */ int ft_strncmp(const char *s1, const char *s2, size_t n) { size_t i; diff --git a/str/ft_strncpy.c b/str/ft_strncpy.c index d8db173..932677e 100644 --- a/str/ft_strncpy.c +++ b/str/ft_strncpy.c @@ -6,21 +6,12 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/31 16:14:10 by rparodi #+# #+# */ -/* Updated: 2025/09/01 18:46:55 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include -/** - * @brief Copies a string. - * - * @param dst The destination buffer. - * @param src The source string. - * @param size The size to copy - * - * @return A pointer to `dst`. - */ char *ft_strcpy(char *dst, const char *src, size_t size) { size_t i; diff --git a/str/ft_strnstr.c b/str/ft_strnstr.c index 8949913..d227b60 100644 --- a/str/ft_strnstr.c +++ b/str/ft_strnstr.c @@ -6,26 +6,12 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/07 16:57:44 by rparodi #+# #+# */ -/* Updated: 2025/09/01 17:54:58 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include -/** - * @brief Locates a substring within a string, up to a specified length. - * - * The `ft_strnstr` function locates the first occurrence of the null-terminated - * string `needle` within the string `haystack`, - * searching only up to `len` characters. - * - * @param big The string to search. - * @param little The substring to locate. - * @param len The maximum number of characters to search. - * - * @return A pointer to the beginning of the located substring, - * or NULL if `needle` is not found. - */ char *ft_strnstr(const char *big, const char *little, size_t len) { size_t i; diff --git a/str/ft_strrchr.c b/str/ft_strrchr.c index b53358e..e75d8d6 100644 --- a/str/ft_strrchr.c +++ b/str/ft_strrchr.c @@ -6,22 +6,13 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/07 16:58:22 by rparodi #+# #+# */ -/* Updated: 2025/09/01 17:49:39 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "str.h" #include -/** - * @brief Locates the last occurrence of a character in a string. - * - * @param s The string to search. - * @param c The character to locate. - * - * @return A pointer to the matched character, - * or NULL if it does not appear in `s`. - */ char *ft_strrchr(const char *s, int c) { size_t i; diff --git a/str/ft_strtrim.c b/str/ft_strtrim.c index b5ccf5e..89df743 100644 --- a/str/ft_strtrim.c +++ b/str/ft_strtrim.c @@ -6,21 +6,13 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/09 13:55:44 by rparodi #+# #+# */ -/* Updated: 2025/09/01 18:26:20 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:16:46 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "str.h" #include -/** - * @brief Trims specified characters from the start and end of a string. - * - * @param s1 The string to trim. - * @param set The set of characters to remove. - * - * @return A pointer to the trimmed string, or NULL if memory allocation fails. - */ char *ft_strtrim(char const *s1, char const *set) { size_t i; diff --git a/str/ft_substr.c b/str/ft_substr.c index 8c1aecc..66b3480 100644 --- a/str/ft_substr.c +++ b/str/ft_substr.c @@ -6,22 +6,13 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/11/09 13:54:42 by rparodi #+# #+# */ -/* Updated: 2025/09/01 18:26:29 by rparodi ### ########.fr */ +/* Updated: 2025/09/05 16:17:50 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #include "str.h" #include -/** - * @brief Extracts a substring from a string. - * - * @param s The source string. - * @param start The starting index of the substring. - * @param len The maximum length of the substring. - * - * @return A pointer to the substring, or NULL if memory allocation fails. - */ char *ft_substr(char const *s, unsigned int start, size_t len) { char *str;