-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_init.c
36 lines (32 loc) · 967 Bytes
/
string_init.c
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
/*
** EPITECH PROJECT, 2024
** ppool05
** File description:
** init
*/
#include <stdlib.h>
#include <string.h>
#include "string.h"
void string_init(string_t *this, const char *s)
{
if (this == NULL || s == NULL)
return;
*this = (string_t){ 0 };
*this = (string_t){
.str = strdup(s),
.assign_c = &assign_c, .assign_s = &assign_s, .append_c = &append_c,
.append_s = &append_s, .at = &at, .clear = &clear, .length = &length,
.compare_c = &compare_c, .compare_s = &compare_s, .copy = ©,
.c_str = &c_str, .empty = &empty, .find_c = &find_c, .find_s = &find_s,
.insert_c = &insert_c, .insert_s = &insert_s, .to_int = &to_int,
.split_c = &split_c, .split_s = &split_s, .print = &print,
.join_c = &join_c, .join_s = &join_s,
};
}
void string_destroy(string_t *this)
{
if (this == NULL || this->str == NULL)
return;
free(this->str);
*this = (string_t){ 0 };
}