mirror of https://github.com/yshui/picom.git
string_utils: add starts_with
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
7899bafb88
commit
7a69534633
|
@ -2,7 +2,9 @@
|
||||||
// Copyright (c) Yuxuan Shui <yshuiv7@gmail.com>
|
// Copyright (c) Yuxuan Shui <yshuiv7@gmail.com>
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "compiler.h"
|
#include "compiler.h"
|
||||||
|
|
||||||
|
@ -59,6 +61,13 @@ static inline char *skip_space_mut(char *src) {
|
||||||
#define skip_space(x) \
|
#define skip_space(x) \
|
||||||
_Generic((x), char *: skip_space_mut, const char *: skip_space_const)(x)
|
_Generic((x), char *: skip_space_mut, const char *: skip_space_const)(x)
|
||||||
|
|
||||||
|
static inline bool starts_with(const char *str, const char *needle, bool ignore_case) {
|
||||||
|
if (ignore_case) {
|
||||||
|
return strncasecmp(str, needle, strlen(needle));
|
||||||
|
}
|
||||||
|
return strncmp(str, needle, strlen(needle));
|
||||||
|
}
|
||||||
|
|
||||||
/// Similar to `asprintf`, but it reuses the allocated memory pointed to by `*strp`, and
|
/// Similar to `asprintf`, but it reuses the allocated memory pointed to by `*strp`, and
|
||||||
/// reallocates it if it's not big enough.
|
/// reallocates it if it's not big enough.
|
||||||
int asnprintf(char **strp, size_t *capacity, const char *fmt, ...);
|
int asnprintf(char **strp, size_t *capacity, const char *fmt, ...);
|
||||||
|
|
Loading…
Reference in New Issue