29 lines
703 B
C
29 lines
703 B
C
#ifndef STRING_VIEW_H
|
|
#define STRING_VIEW_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
|
|
typedef struct StringView {
|
|
char *text;
|
|
size_t length;
|
|
} StringView;
|
|
|
|
#define SV_NULL (StringView){.text = NULL, .length = 0}
|
|
|
|
StringView sv_from_cstr(const char *);
|
|
|
|
void sv_left(StringView *sv, size_t l);
|
|
void sv_right(StringView *sv, size_t l);
|
|
|
|
void sv_ltrim(StringView *sv);
|
|
void sv_rtrim(StringView *sv);
|
|
void sv_trim(StringView *sv);
|
|
|
|
int sv_index_of(StringView sv, char c);
|
|
StringView sv_chop_by_delim(StringView *sv, char delim);
|
|
bool sv_equals(StringView *sv1, StringView *sv2);
|
|
bool sv_starts_with(StringView *sv, StringView *prefix);
|
|
bool sv_ends_with(StringView *sv, StringView *suffix);
|
|
#endif
|