Archeus 0.0.0
A C library and game engine that focuses on documentation
Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1#ifndef ARC_STD_STRING_H_
2#define ARC_STD_STRING_H_
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <stdint.h>
9#include "bool.h"
10
11/**
12 * @brief substring position within a string
13*/
14typedef struct ARC_String {
15 char *data;
16 uint64_t length;
18
19/**
20 * @brief creates ARC_String type
21 *
22 * @param string ARC_String to create
23 * @param data cstring that will be stored in ARC_String
24 * @param length length of ARC_String
25 */
26void ARC_String_Create(ARC_String **string, char *data, uint64_t length);
27
28/**
29 * @brief creates ARC_String type with strinlen
30 *
31 * @param string ARC_String to create
32 * @param data cstring that will be stored in ARC_String
33 */
34void ARC_String_CreateWithStrlen(ARC_String **string, char *data);
35
36/**
37 * @brief creates an empty ARC_String type, useful if you want to add to the string over time without having to keep adding to the size
38 *
39 * @param string ARC_String to create
40 * @param length length of ARC_String
41 */
42void ARC_String_CreateEmpty(ARC_String **string, uint64_t length);
43
44/**
45 * @brief destroys ARC_String type
46 *
47 * @param string string that will be destroyed
48 */
50
51/**
52 * @brief copy a ARC_String
53 *
54 * @param copy copy of oldString, will be set to NULL on error
55 * @param original original string that is being copied
56*/
57void ARC_String_Copy(ARC_String **copy, ARC_String *original);
58
59/**
60 * @brief copy a subtring from a givin ARC_String
61 *
62 * @param substring new coppied substring, will be null on error
63 * @param original string to copy substring from
64 * @param start starting index in relation on original
65 * @param length length of substring that is being created
66*/
67void ARC_String_CopySubstring(ARC_String **substring, ARC_String *original, uint64_t start, uint64_t length);
68
69/**
70 * @brief replaces a string with a section of itself
71 *
72 * @note this uses ARC_String_CopySubstring so errors logs will be thrown in that function not this one
73 *
74 * @param string the string to replace, will not change on error
75 * @param start the starting index of the substring
76 * @param length the length of the substring
77*/
78void ARC_String_ReplaceWithSubstring(ARC_String **string, uint64_t start, uint64_t length);
79
80/**
81 * @brief copy a subtring from a givin ARC_String
82 *
83 * @param newString string that doesn't have substring in it, will be null on error
84 * @param original string to remove substring from
85 * @param substring substring to remove
86*/
87void ARC_String_RemoveSubstring(ARC_String **newString, ARC_String *original, ARC_String *substring);
88
89/**
90 * @brief appends to an ARC_String with an ARC_String
91 *
92 * @note this uses ARC_String_AppendCString, so debug logs will be thrown in that function not this one
93 *
94 * @param string the string to add to, will not change on error
95 * @param append the string that will be added to the back of string
96*/
97void ARC_String_Append(ARC_String **string, ARC_String *append);
98
99/**
100 * @brief appends to an ARC_String with an ARC_String
101 *
102 * @param string the string to add to, will not change on error
103 * @param cstring the cstring that will be added to the back of string
104 * @param length the length of the cstring that is being added
105*/
106void ARC_String_AppendCString(ARC_String **string, const char *cstring, uint64_t length);
107
108/**
109 * @brief appends to an ARC_String with an ARC_String
110 *
111 * @note this uses ARC_String_AppendCString, so debug logs will be thrown in that function not this one
112 *
113 * @param string the string to add to, will not change on error
114 * @param cstring the cstring that will be added to the back of string
115*/
116void ARC_String_AppendCStringWithStrlen(ARC_String **string, const char *cstring);
117
118/**
119 * @brief checks if two strings are the same
120 *
121 * @param first string to check against second
122 * @param second string to check against first
123 *
124 * @return ARC_True if match, ARC_False if they don't match
125 */
127
128/**
129 * @brief check if ARC_String and cstring match
130 *
131 * @param string ARC_string to check
132 * @param cstring cstring to check
133 * @param length length of cstring
134 *
135 * @return ARC_True if match, ARC_False if they don't match
136*/
137ARC_Bool ARC_String_EqualsCString(ARC_String *string, const char *cstring, uint64_t length);
138
139/**
140 * @brief check if ARC_String and cstring match
141 *
142 * @note will use strlen to get the length of the cstring
143 *
144 * @param string ARC_string to check
145 * @param cstring cstring to check
146 *
147 * @return ARC_True if match, ARC_False if they don't match
148*/
150
151/**
152 * @brief check if substring of first equals second string
153 *
154 * @param first string to check against second
155 * @param offset postion based on first to start comparing against second
156 * @param second string to check against first
157 *
158 * @return ARC_True if match, ARC_False if they don't match
159*/
161
162/**
163 * @brief check if ARC_String and cstring match
164 *
165 * @param string ARC_string to check
166 * @param offset postion based on string to start comparing against cstring
167 * @param cstring cstring to check
168 * @param length length of cstring
169 *
170 * @return ARC_True if match, ARC_False if they don't match
171*/
172ARC_Bool ARC_String_SubstringEqualsCString(ARC_String *string, uint64_t offset, const char *cstring, uint64_t length);
173
174/**
175 * @brief checks if string is alphabetic
176 *
177 * @param string string to check
178 *
179 * @return ARC_True if alphabetic, ARC_False if not alphabetic
180 */
182
183/**
184 * @brief checks if string is made out of only numbers
185 *
186 * @param string string to check
187 *
188 * @return ARC_True if it is numeric, ARC_False if it is not numeric
189 */
191
192/**
193 * @brief converst substring from string to uint64_t
194 *
195 * @param string string to convert to uint64_t
196 *
197 * @return uint64_t converted number
198*/
200
201/**
202 * @brief converst substring from string to int64_t
203 *
204 * @param string string to convert to int64_t
205 *
206 * @return int64_t converted number
207*/
209
210/**
211 * @brief converst substring from string to double
212 *
213 * @param string string to convert to double
214 *
215 * @return double converted number
216*/
218
219/**
220 * @brief takes a given string, and assigns index and length for position of first matching substring
221 *
222 * @param string the string that will be searched
223 * @param substr substring to find within string
224 *
225 * @return ~(uint64_t)0 on error, anything else on success
226 */
227uint64_t ARC_String_Find(ARC_String *string, ARC_String *substring);
228
229/**
230 * @brief takes given cstring and gives position of first matching
231 *
232 * @param string the string that will be searched
233 * @param cstring the cstring to find within string
234 * @param length the length of cstring
235 *
236 * @return ~(uint64_t)0 on error, anything else on success
237*/
238uint64_t ARC_String_FindCString(ARC_String *string, const char *cstring, uint64_t length);
239
240/**
241 * @brief takes given cstring and gives position of first matching
242 *
243 * @note will use strlen to get the length of the cstring
244 *
245 * @param string the string that will be searched
246 * @param cstring the cstring to find within string
247 *
248 * @return ~(uint64_t)0 on error, anything else on success
249*/
250uint64_t ARC_String_FindCStringWithStrlen(ARC_String *string, const char *cstring);
251
252/**
253 * @brief takes a given string, and assigns index and length for position of last matching substring
254 *
255 * @param string the string that will be searched
256 * @param substr substring to find within string
257 *
258 * @return ~(uint64_t)0 on error, anything else on success
259 */
260uint64_t ARC_String_FindBack(ARC_String *string, ARC_String *substring);
261
262/**
263 * @brief takes a given cstring and give position of last matching
264 *
265 * @param string the string that will be searched
266 * @param cstring the cstring to find within string
267 * @param length the length of cstring
268 *
269 * @return ~(uint64_t)0 on error, anything else on success
270 */
271uint64_t ARC_String_FindBackCString(ARC_String *string, const char *cstring, uint64_t length);
272
273/**
274 * @brief takes a given cstring and give position of last matching
275 *
276 * @note will use strlen to get the length of the cstring
277 *
278 * @param string the string that will be searched
279 * @param cstring the cstring to find within string
280 *
281 * @return ~(uint64_t)0 on error, anything else on success
282 */
283uint64_t ARC_String_FindBackCStringWithStrlen(ARC_String *string, const char *cstring);
284
285/**
286 * @brief strips the ends based on a given char
287 *
288 * @param stripped where to store the string which has witespace stripped
289 * will be null if there is an error
290 * @param original the string which whill have the matching char stripped from
291 * @param charToStrip the char that will be stripped from the ends
292*/
293void ARC_String_StripEnds(ARC_String **stripped, ARC_String *original, char charToStrip);
294
295/**
296 * @brief strips whitespace from a ARC_String
297 *
298 * @param stripped where to store the string which has witespace stripped
299 * will be null if there is an error
300 * @param original the string which whill have whitespace stripped from
301*/
303
304/**
305 * @brief strips the whitespace from the ends of a string
306 *
307 * @param stripped where to store the string which has witespace stripped from the ends
308 * will be null if there is an error
309 * @param original the string which whill have the whitespace stripped from its ends
310*/
312
313/**
314 * @brief merges two strings together
315 *
316 * @param combined new ARC_String of combined strings frist + second
317 * @param first first part of string to combine
318 * @param second second part of string to combine
319*/
320void ARC_String_Merge(ARC_String **combined, ARC_String *first, ARC_String *second);
321
322/**
323 * @brief copy a subtring from a givin ARC_String
324 *
325 * @param newString new string without specified section, will be NULL on error
326 * @param original string to remove section from
327 * @param removeIndex starting index in relation on original of what is to be removed
328 * @param removeLength length of section that is being removed
329*/
330void ARC_String_RemoveSection(ARC_String **newString, ARC_String *original, uint64_t removeIndex, uint64_t removeLength);
331
332/**
333 * @brief replaces characters in string matching the given pattern
334 *
335 * @note this uses ARC_String_CopyReplaceMatching, so debug logs will be thrown in that function not this one
336 *
337 * @param string the string that will be modified, will discard changes and set arc_errno on fail
338 * @param pattern the pattern to replace in the string on match
339 * @param replacement the string that will replace the matched pattern
340*/
341void ARC_String_ReplaceMatching(ARC_String **string, ARC_String *pattern, ARC_String *replacement);
342
343/**
344 * @brief replaces characters in a copy of a string matching the given pattern
345 *
346 * @note original will not be modified
347 * @note newString will need to be destroyed if it is not set to NULL
348 *
349 * @param newString an empty string that this function will fill with a copy with replacements, will be set to NULL and arc_errno set on fail
350 * @param original the original string that will be copied
351 * @param pattern the pattern to replace in the string on match
352 * @param replacement the string that will replace the matched pattern
353*/
354void ARC_String_CopyReplaceMatching(ARC_String **newString, ARC_String *original, ARC_String *pattern, ARC_String *replacement);
355
356/**
357 * @brief replaces characters in string matching the given pattern
358 *
359 * @param string the string that will be modified, will discard changes and set arc_errno on fail
360 * @param patternCString the cstring pattern to replace in the string on match
361 * @param patternLength the lenght of the cstring pattern
362 * @param replacementCstring the cstring that will replace the matched pattern
363 * @param replacementLength the length of the cstring replacement
364*/
365void ARC_String_ReplaceMatchingCString(ARC_String **string, char *patternCString, uint64_t patternLength, char *replacementCString, uint64_t replacementLength);
366
367/**
368 * @brief replaces characters in string matching the given pattern
369 *
370 * @note this uses ARC_String_ReplaceMatchingCString, so debug logs will be thrown in that function not this one
371 *
372 * @param string the string that will be modified, will discard changes and set arc_errno on fail
373 * @param patternCString the cstring pattern to replace in the string on match
374 * @param replacementCstring the cstring that will replace the matched pattern
375*/
376void ARC_String_ReplaceMatchingCStringWithStrlen(ARC_String **string, char *patternCString, char *replacement);
377
378#ifdef __cplusplus
379}
380#endif
381
382#endif //ARC_STD_STRING_H_
#define ARC_Bool
Definition bool.h:10
uint64_t ARC_String_ToUint64_t(ARC_String *string)
converst substring from string to uint64_t
void ARC_String_StripEndsWhitespace(ARC_String **stripped, ARC_String *original)
strips the whitespace from the ends of a string
void ARC_String_RemoveSubstring(ARC_String **newString, ARC_String *original, ARC_String *substring)
copy a subtring from a givin ARC_String
int64_t ARC_String_ToInt64_t(ARC_String *string)
converst substring from string to int64_t
void ARC_String_AppendCStringWithStrlen(ARC_String **string, const char *cstring)
appends to an ARC_String with an ARC_String
void ARC_String_ReplaceMatchingCStringWithStrlen(ARC_String **string, char *patternCString, char *replacement)
replaces characters in string matching the given pattern
void ARC_String_Merge(ARC_String **combined, ARC_String *first, ARC_String *second)
merges two strings together
uint64_t ARC_String_FindCStringWithStrlen(ARC_String *string, const char *cstring)
takes given cstring and gives position of first matching
ARC_Bool ARC_String_EqualsCString(ARC_String *string, const char *cstring, uint64_t length)
check if ARC_String and cstring match
void ARC_String_CopySubstring(ARC_String **substring, ARC_String *original, uint64_t start, uint64_t length)
copy a subtring from a givin ARC_String
uint64_t ARC_String_FindBack(ARC_String *string, ARC_String *substring)
takes a given string, and assigns index and length for position of last matching substring
uint64_t ARC_String_FindBackCStringWithStrlen(ARC_String *string, const char *cstring)
takes a given cstring and give position of last matching
void ARC_String_CreateWithStrlen(ARC_String **string, char *data)
creates ARC_String type with strinlen
void ARC_String_AppendCString(ARC_String **string, const char *cstring, uint64_t length)
appends to an ARC_String with an ARC_String
void ARC_String_Create(ARC_String **string, char *data, uint64_t length)
creates ARC_String type
void ARC_String_CopyReplaceMatching(ARC_String **newString, ARC_String *original, ARC_String *pattern, ARC_String *replacement)
replaces characters in a copy of a string matching the given pattern
uint64_t ARC_String_FindBackCString(ARC_String *string, const char *cstring, uint64_t length)
takes a given cstring and give position of last matching
ARC_Bool ARC_String_EqualsCStringWithStrlen(ARC_String *string, const char *cstring)
check if ARC_String and cstring match
void ARC_String_Copy(ARC_String **copy, ARC_String *original)
copy a ARC_String
ARC_Bool ARC_String_SubstringEquals(ARC_String *first, uint64_t offset, ARC_String *second)
check if substring of first equals second string
void ARC_String_Append(ARC_String **string, ARC_String *append)
appends to an ARC_String with an ARC_String
ARC_Bool ARC_String_SubstringEqualsCString(ARC_String *string, uint64_t offset, const char *cstring, uint64_t length)
check if ARC_String and cstring match
struct ARC_String ARC_String
substring position within a string
uint64_t ARC_String_FindCString(ARC_String *string, const char *cstring, uint64_t length)
takes given cstring and gives position of first matching
void ARC_String_CreateEmpty(ARC_String **string, uint64_t length)
creates an empty ARC_String type, useful if you want to add to the string over time without having to...
void ARC_String_StripWhitespace(ARC_String **stripped, ARC_String *original)
strips whitespace from a ARC_String
ARC_Bool ARC_String_Equals(ARC_String *first, ARC_String *second)
checks if two strings are the same
ARC_Bool ARC_String_IsAlpha(ARC_String *string)
checks if string is alphabetic
void ARC_String_Destroy(ARC_String *string)
destroys ARC_String type
uint64_t ARC_String_Find(ARC_String *string, ARC_String *substring)
takes a given string, and assigns index and length for position of first matching substring
void ARC_String_ReplaceMatchingCString(ARC_String **string, char *patternCString, uint64_t patternLength, char *replacementCString, uint64_t replacementLength)
replaces characters in string matching the given pattern
double ARC_String_ToDouble(ARC_String *string)
converst substring from string to double
void ARC_String_ReplaceWithSubstring(ARC_String **string, uint64_t start, uint64_t length)
replaces a string with a section of itself
void ARC_String_StripEnds(ARC_String **stripped, ARC_String *original, char charToStrip)
strips the ends based on a given char
void ARC_String_RemoveSection(ARC_String **newString, ARC_String *original, uint64_t removeIndex, uint64_t removeLength)
copy a subtring from a givin ARC_String
ARC_Bool ARC_String_IsNumeric(ARC_String *string)
checks if string is made out of only numbers
void ARC_String_ReplaceMatching(ARC_String **string, ARC_String *pattern, ARC_String *replacement)
replaces characters in string matching the given pattern
substring position within a string
Definition string.h:14
uint64_t length
Definition string.h:16
char * data
Definition string.h:15