-
-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yuxuan Shui <[email protected]>
- Loading branch information
Showing
1 changed file
with
9 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ | |
// Copyright (c) Yuxuan Shui <[email protected]> | ||
#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, ...); |