/*
** EPITECH PROJECT, 2018
** task01
** File description:
** I do task
*/
#include "lib/my_string.h"

char *my_strstr(const char *haystack, const char *needle)
{
    ssize_t needle_len;
    size_t len;

    len = 0;
    haystack--;
    needle_len = -1;
    while (needle[++needle_len] != '\0');
    while (*(++haystack) != '\0' && needle[len] != '\0')
        len = (*haystack == needle[len]) ? len + 1 : 0;
    return ((needle[len] == '\0') ? (char*)haystack - needle_len : NULL);
}

char *my_strcasestr(const char *haystack, const char *needle)
{
    size_t needle_len;
    ssize_t len;

    len = 0;
    haystack--;
    needle_len = -1;
    while (needle[++needle_len] != '\0');
    while (*(++haystack) != '\0' && needle[len] != '\0')
        len = (*haystack == needle[len]
        || *haystack - 'A' + 'a' == needle[len]
        || *haystack == needle[len] - 'A' + 'a') ? len + 1 : 0;
    return ((needle[len] == '\0') ? (char*)haystack - needle_len : NULL);
}
