Skip to content

Commit 931c84a

Browse files
Adding new cstring functions
1 parent d5aad4a commit 931c84a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

code/logic/cstring.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,28 @@ cstring fossil_io_cstring_pad_right(ccstring str, size_t total_length, char pad_
334334
return result;
335335
}
336336

337+
int fossil_io_cstring_icmp(const char *str1, const char *str2) {
338+
while (*str1 && *str2) {
339+
if (tolower((unsigned char)*str1) != tolower((unsigned char)*str2)) {
340+
return 0; // Not equal
341+
}
342+
str1++;
343+
str2++;
344+
}
345+
return (*str1 == '\0' && *str2 == '\0'); // Both strings must end at the same time
346+
}
347+
348+
int fossil_io_cstring_icontains(ccstring str, ccstring substr) {
349+
const char *p = str;
350+
while (*p) {
351+
if (fossil_io_cstring_icmp(p, substr) == 1) {
352+
return 1; // Found
353+
}
354+
p++;
355+
}
356+
return 0; // Not found
357+
}
358+
337359
// ============================================================================
338360
// String Stream Functions
339361
// ============================================================================

0 commit comments

Comments
 (0)