mirror of
https://github.com/yshui/picom.git
synced 2025-04-21 18:03:02 -04:00
string_utils: add starts_with
Signed-off-by: Yuxuan Shui <yshuiv7@gmail.com>
This commit is contained in:
parent
7899bafb88
commit
7a69534633
1 changed files with 9 additions and 0 deletions
|
@ -2,7 +2,9 @@
|
|||
// Copyright (c) Yuxuan Shui <yshuiv7@gmail.com>
|
||||
#pragma once
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
|
@ -59,6 +61,13 @@ static inline char *skip_space_mut(char *src) {
|
|||
#define skip_space(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
|
||||
/// reallocates it if it's not big enough.
|
||||
int asnprintf(char **strp, size_t *capacity, const char *fmt, ...);
|
||||
|
|
Loading…
Add table
Reference in a new issue