`ls`/checks.h: move `startsWith*` functions to header.
i figure these'll be useful in other programs, so might as well go ahead and add them.master
parent
6f27014976
commit
42e3204429
@ -0,0 +1,26 @@
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
static bool startsWithChar(const char *pre, const char str) {
|
||||
char *e;
|
||||
int index;
|
||||
e = strchr(pre, str);
|
||||
index = (int)(e - pre);
|
||||
return index == 0;
|
||||
}
|
||||
|
||||
static bool startsWithStr(char *prefix, char *string) {
|
||||
if (strlen(prefix) > strlen(string)) {
|
||||
return false;
|
||||
}
|
||||
int max = strlen(prefix);
|
||||
int i = 0;
|
||||
do {
|
||||
if (prefix[i] == string[i]) {
|
||||
i++;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} while (i < max);
|
||||
return true;
|
||||
}
|
Loading…
Reference in new issue