docs(str): moving the actual documentation on the header

- The documentation on the header allow u to see on the files where the
header is inclued
This commit is contained in:
Raphael 2025-09-05 16:30:00 +02:00
parent 701ce57f84
commit 2cf0714dc7
No known key found for this signature in database
18 changed files with 189 additions and 172 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stddef.h>
/**
* @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

View file

@ -6,7 +6,7 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,22 +6,13 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <unistd.h>
/**
* @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;

View file

@ -6,23 +6,12 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <unistd.h>
/**
* @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;

View file

@ -6,20 +6,12 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <unistd.h>
/**
* @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;

View file

@ -6,21 +6,13 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.h>
/**
* @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;

View file

@ -6,20 +6,12 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <unistd.h>
/**
* @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;

View file

@ -6,22 +6,13 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.h>
/**
* @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;

View file

@ -6,7 +6,7 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -6,22 +6,13 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <unistd.h>
/**
* @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;

View file

@ -6,19 +6,12 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <unistd.h>
/**
* @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;

View file

@ -6,7 +6,7 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.h>
/**
* @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;

View file

@ -6,21 +6,12 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <unistd.h>
/**
* @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;

View file

@ -6,21 +6,12 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stddef.h>
/**
* @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;

View file

@ -6,26 +6,12 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <unistd.h>
/**
* @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;

View file

@ -6,22 +6,13 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <unistd.h>
/**
* @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;

View file

@ -6,21 +6,13 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.h>
/**
* @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;

View file

@ -6,22 +6,13 @@
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <stdlib.h>
/**
* @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;