<commit_before>#include <stdlib.h>
#include <ctype.h>
#include <string.h>

#include "str.h"

char *strchr_rev(const char *s, int ch, const char *start)
{
	while(*s != ch){
		if(s == start)
			return NULL;
		s--;
	}
	return (char *)s; /* *s == ch */
}

char *tim_strrevstr(char *restrict haystack, unsigned off, const char *restrict needle)
{
	const size_t nlen = strlen(needle);

	for(char *p = haystack + off;
			p >= haystack;
			p--)
	{
		if(!strncmp(p, needle, nlen))
			return p;
	}

	return NULL;
}

char *tim_strstr(char *restrict haystack, size_t len, const char *restrict needle)
{
	/* memstr */
	for(size_t h = 0; h < len; h++)
		if(haystack[h] == *needle)
			/* can assume needle is 0-terminated */
			for(size_t n = 0; n < len - h; n++)
				if(!needle[n])
					return haystack + h;
				else if(haystack[h + n] != needle[n])
					break;

	return NULL;
}

bool isallspace(const char *s)
{
	for(; *s && isspace(*s); s++);<commit_msg>Fixed search logic for matches at the end of the line<commit_after>#include <stdlib.h>
#include <ctype.h>
#include <string.h>

#include "str.h"

char *strchr_rev(const char *s, int ch, const char *start)
{
	while(*s != ch){
		if(s == start)
			return NULL;
		s--;
	}
	return (char *)s; /* *s == ch */
}

char *tim_strrevstr(char *restrict haystack, unsigned off, const char *restrict needle)
{
	const size_t nlen = strlen(needle);

	for(char *p = haystack + off;
			p >= haystack;
			p--)
	{
		if(!strncmp(p, needle, nlen))
			return p;
	}

	return NULL;
}

char *tim_strstr(char *restrict haystack, size_t len, const char *restrict needle)
{
	if(!*needle)
		return NULL;

	/* memstr */
	for(size_t h = 0; h < len; h++)
		if(haystack[h] == *needle)
			/* can assume needle is 0-terminated */
			for(size_t n = 0; n < len - h;){
				if(haystack[h + n] != needle[n])
					break;
				n++;
				if(!needle[n])
					return haystack + h;
			}

	return NULL;
}

bool isallspace(const char *s)
{
	for(; *s && isspace(*s); s++);
{'fraction_non_alphanumeric': 0.17346938775510204, 'fraction_numerical': 0.003061224489795918, 'mean_word_length': 3.2354211663066956, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5534278', 'n_tokens_mistral': 878, 'n_tokens_neox': 792, 'n_words': 225}