You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
624 B
C

#pragma once
#include <stdbool.h>
#include <string.h>
#define SV_LIT(S) (S "LITERAL_CHECK", (str_view_t) { S, sizeof(S) - 1 })
#define SV_NULL ((str_view_t) { NULL, 0 })
typedef struct {
const char *ptr;
size_t len;
} str_view_t;
static inline str_view_t sv_from_parts(const char *ptr, size_t len) {
return (str_view_t) { ptr, len };
}
static inline str_view_t sv_from_cstr(const char *ptr, size_t maxlen) {
size_t len = strnlen(ptr, maxlen);
return sv_from_parts(ptr, len);
}
static inline str_view_t sv_from_cstr_unbounded(const char *ptr) {
size_t len = strlen(ptr);
return sv_from_parts(ptr, len);
}