-
Notifications
You must be signed in to change notification settings - Fork 30
/
text.h
122 lines (107 loc) · 2.67 KB
/
text.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
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
/**
* @file text.h
*
* @author hutusi ([email protected])
*
* @brief Text string. (similar to string in C++.)
*
* The most difference between Text and char string is:
*
* Text can contain '\0', NIL, or any charactor.
*
* @date 2019-08-15
*
* @copyright Copyright (c) 2019, hutusi.com
*
*/
#ifndef RETHINK_C_TEXT_H
#define RETHINK_C_TEXT_H
/**
* @brief Definition of a @ref Text.
*
*/
typedef struct _Text Text;
#define CHAR_NIL 0
/**
* @brief Allocate a new empty Text.
*
* @return Text* The new Text if success, otherwise NULL.
*/
Text *text_new();
/**
* @brief New a new Text from a string.
*
* @param string The original string.
* @return Text* Return new Text if success, otherwise NULL.
*/
Text *text_from(const char *string);
/**
* @brief New a new Text from a string with length.
*
* @param string The original string.
* @param length The length of the string.
* @return Text* The new Text if success, otherwise NULL.
*/
Text *text_n_from(const char *string, int length);
/**
* @brief Delete a Text and free back memory.
*
* @param text The Text to delete.
*/
void text_free(Text *text);
/**
* @brief Clone a new text from text.
*
* @param text The text.
* @return Text* The clone new text.
*/
Text *text_clone(const Text *text);
/**
* @brief Convert a text as a const char string.
*
* @param text The text.
* @return const char* The char string.
*/
const char *text_char_string(const Text *text);
/**
* @brief Get the length of a text.
*
* @param text The text.
* @return unsigned int The length.
*/
unsigned int text_length(const Text *text);
/**
* @brief Get the indicated index charactor of a text.
*
* @param text The text.
* @param index The indicated index.
* @return char The charactor.
*/
char text_char_at(const Text *text, unsigned int index);
/**
* @brief Compare two text.
*
* @param text1 One text.
* @param text2 Another text.
* @return int 1 if the first text greater than the second; -1 if the
* second text greater than the first; 0 if two text have same
* content.
*/
int text_compare(const Text *text1, const Text *text2);
/**
* @brief Judge the equality of two text's content.
*
* @param text1 One text.
* @param text2 Another text.
* @return int Return 1 if equal, otherwise return 0.
*/
int text_equal(const Text *text1, const Text *text2);
/**
* @brief Append a charactor to a Text.
*
* @param text The Text.
* @param ch The charactor.
* @return Text* The appended Text.
*/
Text *text_append(Text *text, char ch);
#endif /* #ifndef RETHINK_C_TEXT_H */