-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstr.h
89 lines (76 loc) · 1.68 KB
/
str.h
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
/**
* Implementace překladače imperativního jazyka IFJ22
*
* @file str.h
* @author Josef Kuchař ([email protected])
* @author Matej Sirovatka ([email protected])
* @author Tomáš Běhal ([email protected])
* @author Šimon Benčík ([email protected])
* @brief Declaration of helper functions for working with dynamic strings
*/
#ifndef __STR_H__
#define __STR_H__
#include <stdbool.h>
#include <stdlib.h>
// String
typedef struct {
char* val; // Actual string
size_t len; // Length
size_t size; // Buffer size
} str_t;
/**
* @brief Initialize new empty string
*
* @return Initiazed string
*/
str_t str_new();
/**
* @brief Initialize string from existing string
*
* @param str Existing string (source)
* @return Copied string
*/
str_t str_new_from_str(str_t* str);
/**
* @brief Free existing string
*
* @param str String to be freed
*/
void str_free(str_t* str);
/**
* @brief Add character to string
*
* @param str String to which the character will be added
*/
void str_add_char(str_t* str, char c);
/**
* @brief Add c-string to existing string
*
* @param str String to which the other string will be added
* @param cstr C-String
*/
void str_add_cstr(str_t* str, char* cstr);
/**
* @brief Add string to existing string
*
* @param str Destination string
* @param str2 Source string
*/
void str_add_str(str_t* str, str_t* str2);
/**
* @brief Add int to existing string
*
* @param str Destination string
* @param i Source int
*/
void str_add_int(str_t* str, int i);
/**
* @brief Clear string
*/
void str_clear(str_t* str);
/**
* @brief Print string
*
*/
void str_print(str_t* str);
#endif // __STR_H__