/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_strnstr.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: thrieg +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/14 17:50:28 by thrieg #+# #+# */ /* Updated: 2025/02/16 19:05:13 by thrieg ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" char *ft_strnstr(const char *big, const char *little, size_t len) { size_t i; size_t j; if (*little == '\0') return ((char *)big); i = 0; while (big[i] != '\0' && i < len) { j = 0; while (little[j] != '\0' && big[i + j] == little[j] && (i + j) < len) j++; if (little[j] == '\0') return ((char *)big + i); i++; } return (NULL); } int ft_strhassuffix(const char *s, const char *suffix) { size_t i; size_t j; i = ft_strlen(s); j = ft_strlen(suffix); if (i == 0 || j == 0) return (0); i--; j--; while (i > 0 && j > 0) { if (s[i] != suffix[j]) return (0); i--; j--; } return (1); } /* * Same as ft_strcmp() but ignores eventual `\n` in the * comparison. */ int ft_linecmp(const char *s1, const char *s2) { size_t i; const unsigned char *a; const unsigned char *b; i = 0; a = (const unsigned char *) s1; b = (const unsigned char *) s2; while (1) { if ((a[i] == '\n' && b[i] == '\0') || (a[i] == '\0' && b[i] == '\n')) break ; if (a[i] != b[i]) return (a[i] - b[i]); if (a[i] == '\0') break ; i++; } return (0); } size_t ft_linelen(const char *line) { size_t i; i = 0; while (line[i] != '\0' && line[i] != '\n') i++; return (i); }