summaryrefslogtreecommitdiff
path: root/str.h
blob: 0b3e5390f9388661dcf820e2edb532d75b1e85b1 (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
28
29
30
31
32
#ifndef __SAFEC_STR_H
#define __SAFEC_STR_H
#include "types.h"

typedef struct {
    size_t length;
    char* __data;
} str_t;

char* str_at(const str_t* str, size_t idx);
str_t str_slice(const str_t* str, size_t start, size_t length);
int str_cmp(const str_t* s1, const str_t* s2);

/* not found = -1 */
ssize_t str_indexof(const str_t* str, char c);
ssize_t str_rindexof(const str_t* str, char c);

str_t str_heap_dup(const str_t* str);
str_t str_heap_cat(const str_t* s1, const str_t* s2);

/* TODO: implement string.h functions for this new string construct */

/* `dst` will be overwritten with the contents of `src` */
void str_to_c_str(char* dst, size_t dst_size, const str_t* src);
char* str_to_heap_c_str(const str_t* str);

str_t str_heap_alloc(size_t length);
str_t str_heap_init(const char* c_str, size_t length);
str_t str_heap_init_slice(const char* c_str, size_t start, size_t length);
void str_heap_destroy(str_t* str);

#endif