This seems to be as close as I can get it to my style. I'd've wanted to also set Cpp11BracedListStyle[1] to Block, but that ended up misformatting some compound literals that included expressions with binary operators. I'm also unsure what is going on with the formatting of _Generic(). [1] https://clang.llvm.org/docs/ClangFormatStyleOptions.html#cpp11bracedliststyle
26 lines
694 B
C
26 lines
694 B
C
#include <string.h>
|
|
|
|
#include "bytestr.h"
|
|
#include "vector.h"
|
|
|
|
bool str_eq(SPAN(char) a, SPAN(char) b) {
|
|
if (LENGTH(a) != LENGTH(b)) {
|
|
return false;
|
|
} else if (LENGTH(a) == 0) {
|
|
// AT(_, 0) would panic here, so we need to handle the case of
|
|
// zero length strings separately. Fortunately we know that both
|
|
// a and b are the same length, and that length is zero, so they
|
|
// cannot be different.
|
|
return true;
|
|
} else {
|
|
return !memcmp(&AT(a, 0), &AT(b, 0), LENGTH(a));
|
|
}
|
|
}
|
|
|
|
bool starts_with(SPAN(char) string, SPAN(char) prefix) {
|
|
if (LENGTH(string) < LENGTH(prefix)) {
|
|
return false;
|
|
}
|
|
auto substring = SLICE(string, 0, LENGTH(prefix));
|
|
return str_eq(substring, prefix);
|
|
}
|