aboutsummaryrefslogtreecommitdiff
path: root/include/slice.h
blob: 26f9fd7d6eb8febcad2dcf8103b626a0f998168b (plain)
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
#ifndef CMONKEY_SLICE_H
#define CMONKEY_SLICE_H

#include <sys/types.h>

struct slice {
	const char *str;
	size_t start;
	size_t end;
};

struct slice slice_new(const char *str, size_t start, size_t end);

struct slice slice_fullstr(const char *str);

void slice_set(struct slice *, const char *str, size_t start, size_t end);

size_t slice_len(const struct slice *);

/* Returns 0 if equal, 1 if a > b, -1 if a < b */
int slice_cmp(const struct slice *restrict a, const struct slice *restrict b);

void slice_cpy(struct slice *dst, const struct slice *src);

char *slice_sprint(struct slice *, char *str);

#endif