diff options
author | 2023-02-03 18:40:59 +0100 | |
---|---|---|
committer | 2023-02-03 18:40:59 +0100 | |
commit | 51c05fe7b5d6518bfb8a07ee3ec3c072bb21163e (patch) | |
tree | 92a52dc4849fbeb2566f8e87a88ff3ec02e5f75e /src | |
download | string2-51c05fe7b5d6518bfb8a07ee3ec3c072bb21163e.tar.gz string2-51c05fe7b5d6518bfb8a07ee3ec3c072bb21163e.zip |
Initial commit
Diffstat (limited to 'src')
-rw-r--r-- | src/string2.c | 46 | ||||
-rw-r--r-- | src/string2.h | 11 |
2 files changed, 57 insertions, 0 deletions
diff --git a/src/string2.c b/src/string2.c new file mode 100644 index 0000000..332dbf7 --- /dev/null +++ b/src/string2.c @@ -0,0 +1,46 @@ +/* See LICENSE file for copyright and license details. */ + +#include <stdio.h> +#include <string.h> + +int +strends(const char *str, const char *end) +{ + int size_s1 = strlen(str); + int size_s2 = strlen(end); + + int i = size_s1 - 1, j = size_s2 - 1; + + if (size_s2 > size_s1) { + return 1; + } + + for (; i >= 0 && j >= 0; i--, j--) { + if (str[i] != end[j]) { + return 1; + } + } + + return 0; +} + +int +strstarts(const char *str, const char *end) +{ + int size_s1 = strlen(str); + int size_s2 = strlen(end); + + int i = 0; + + if (size_s2 > size_s1) { + return 1; + } + + for (; i < size_s2; i++) { + if (str[i] != end[i]) { + return 1; + } + } + + return 0; +} diff --git a/src/string2.h b/src/string2.h new file mode 100644 index 0000000..4d79dfd --- /dev/null +++ b/src/string2.h @@ -0,0 +1,11 @@ +/* See LICENSE file for copyright and license details. */ + +#ifndef __STRING2_H__ +#define __STRING2_H__ + +#include <string.h> + +int strends(const char *, const char *); +int strstarts(const char *, const char *); + +#endif /* __STRING2_H__ */ |