summaryrefslogtreecommitdiff
path: root/src/utils.c
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2015-02-24 11:13:38 +0100
committerLukas Fleischer <calcurse@cryptocrack.de>2015-02-24 11:17:38 +0100
commit52779d2ec6391a122cb2822c147d8c1f86e8b6ba (patch)
tree3d095b059dda5dd8763685b4f609b472676d825d /src/utils.c
parentf91208c2f43d6fda12f410840a0a1cd63091a9d3 (diff)
downloadcalcurse-52779d2ec6391a122cb2822c147d8c1f86e8b6ba.zip
Introduce starts_with() and starts_with_ci()
Create user-defined functions to check whether a string contains a certain prefix instead of messing around with strncmp() and strncasecmp(). Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index c7dc61c..ec5a1ea 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -1602,3 +1602,15 @@ asprintf(char **str, const char *format, ...)
return n;
}
+
+int starts_with(const char *s, const char *p)
+{
+ for (; *p && *p == *s; s++, p++);
+ return (*p == '\0');
+}
+
+int starts_with_ci(const char *s, const char *p)
+{
+ for (; *p && tolower(*p) == tolower(*s); s++, p++);
+ return (*p == '\0');
+}