blob: 1153dcb612aab4e4b53d650d98675b0dc2d737e4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
#ifndef ORYX_STRVIEW_H
#define ORYX_STRVIEW_H
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "types.h"
struct strview {
const uchar *p;
size_t len;
};
/* Expand SV into arguments suitable for a call to printf() */
#define SV_PRI_ARGS(sv) ((int)(sv).len), ((sv).p)
/* Convert the string-literal S into a string-view */
#define SV(s) ((struct strview){s, sizeof(s) - 1})
/* Return the hash of SV */
uint64_t strview_hash(struct strview sv);
/* Copy the contents of SV to DST including a null terminator, and return DST */
uchar *svtocstr(uchar *dst, struct strview sv)
__attribute__((returns_nonnull, nonnull));
/* Return whether or not X and Y are equal */
__attribute__((always_inline))
static inline bool
strview_eq(struct strview x, struct strview y)
{
return x.len == y.len && memcmp(x.p, y.p, x.len) == 0;
}
#endif /* !ORYX_STRVIEW_H */
|