Skip to content

Commit

Permalink
Implemented func to check if str has substr at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
iWas-Coder committed Dec 8, 2024
1 parent 6f64d63 commit 4f43348
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions carbon.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ CARBON_API i32 carbon_string_cmp(const char *s1, const char *s2);
CARBON_API char *carbon_string_dup(const char *s);
CARBON_API char *carbon_string_fmt(const char *s, ...);
CARBON_API void carbon_string_strip_substr(char *s, const char *sub);
CARBON_API u8 carbon_string_ends_with_substr(const char *s, const char *sub);

/*
** $$========================$$
Expand Down
5 changes: 5 additions & 0 deletions src/carbon_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ void carbon_string_strip_substr(char *s, const char *sub) {
char *p;
while ((p = strstr(s, sub))) memmove(p, p + len, strlen(p + len) + 1);
}

u8 carbon_string_ends_with_substr(const char *s, const char *sub) {
usz s_len = strlen(s), sub_len = strlen(sub);
return (s_len >= sub_len) && (!carbon_string_cmp(s + (s_len - sub_len), sub));
}

0 comments on commit 4f43348

Please sign in to comment.