summaryrefslogtreecommitdiffhomepage
path: root/src/rodeo_string.c
blob: 8e82b6b37e719ceb499ff76648806705fede1ab1 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

// internal
#include "rodeo.h"
#include "rodeo_types.h"

// external
#define i_implement
#include "stc/cstr.h"
#include "SDL2/SDL.h"

// system
#include <stdarg.h>

// TODO: the create and destroy functions arent actually used together.
// one is a pointer and the other isnt
rodeo_string_t
rodeo_string_create(const char *c_string)
{
	cstr result = cstr_NULL;
	if(c_string != NULL)
	{
		result = cstr_from(c_string);
	}
	return *(rodeo_string_t*)(&result);
}

void
rodeo_string_destroy(rodeo_string_t *self)
{
	cstr_drop((cstr*)self);
	//free(string); // the above already calls free on the entire pointer
}

char*
rodeo_string_to_cstr(rodeo_string_t *self)
{
	return cstr_data((cstr*)self);
}

const char*
rodeo_string_to_constcstr(const rodeo_string_t *self)
{
	return cstr_str((cstr*)self);
}

void
rodeo_string_insert(
	rodeo_string_t *self,
	const rodeo_string_t insert,
	intptr_t position
)
{
	cstr_insert_s((cstr*)self, position, *(cstr*)&insert);
}

void
rodeo_string_append(
	rodeo_string_t *self,
	const rodeo_string_t append
)
{
	rodeo_string_insert(
		self,
		append,
		cstr_size((cstr*)self)
	);
}

void
rodeo_string_prepend(
	rodeo_string_t *self,
	const rodeo_string_t prepend
)
{
	rodeo_string_insert(
		self,
		prepend,
		0
	);
}

void
rodeo_string_clear(rodeo_string_t *self)
{
	cstr_clear((cstr*)self);
}

void
rodeo_string_set(rodeo_string_t *self, char *value)
{
	cstr_clear((cstr*)self);
	cstr *temp = (cstr*)self;
	*temp = cstr_from(value);
}

rodeo_string_t
rodeo_string_clone(const rodeo_string_t self)
{
	cstr temp = cstr_clone(*(cstr*)&self);
	rodeo_string_t result = *(rodeo_string_t*)&temp;
	return result;
}

rodeo_string_t
rodeo_string_format(const char *format, ...)
{
	rodeo_string_t result;
	mrodeo_vargs_do(format)
	{
		cstr temp = cstr_from_vfmt(format, vargs);
		result = *(rodeo_string_t*)&temp;
	}
	return result;
}

rodeo_string_t
rodeo_string_vargs_format(const char *format, va_list vargs)
{
	cstr temp = cstr_from_vfmt(format, vargs);
	rodeo_string_t result = *(rodeo_string_t*)&temp;
	return result;
}