archeus/include/arc/std/string.h

220 lines
No EOL
6.5 KiB
C

#ifndef ARC_STD_STRING_H_
#define ARC_STD_STRING_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
/**
* @brief substring position within a string
*/
typedef struct ARC_String {
char *data;
uint64_t length;
} ARC_String;
/**
* @brief creates ARC_String type
*
* @param string ARC_String to create
* @param data cstring that will be stored in ARC_String
* @param length length of ARC_String
*/
void ARC_String_Create(ARC_String **string, char *data, uint64_t length);
/**
* @brief creates ARC_String type with strinlen
*
* @param string ARC_String to create
* @param data cstring that will be stored in ARC_String
*/
void ARC_String_CreateWithStrlen(ARC_String **string, char *data);
/**
* @brief destroys ARC_String type
*
* @param string string that will be destroyed
*/
void ARC_String_Destroy(ARC_String *string);
/**
* @brief copy a ARC_String
*
* @param copy copy of oldString, will be set to NULL on error
* @param original original string that is being copied
*/
void ARC_String_Copy(ARC_String **copy, ARC_String *original);
/**
* @brief copy a subtring from a givin ARC_String
*
* @param substring new coppied substring, will be null on error
* @param original string to copy substring from
* @param start starting index in relation on original
* @param length length of substring that is being created
*/
void ARC_String_CopySubstring(ARC_String **substring, ARC_String *original, uint64_t start, uint64_t length);
/**
* @brief copy a subtring from a givin ARC_String
*
* @param newString string that doesn't have substring in it, will be null on error
* @param original string to remove substring from
* @param substring substring to remove
*/
void ARC_String_RemoveSubstring(ARC_String **newString, ARC_String *original, ARC_String *substring);
/**
* @brief checks if two strings are the same
*
* @param first string to check against second
* @param second string to check against first
*
* @return 1 if match, 0 if they don't match
*/
uint8_t ARC_String_Equals(ARC_String *first, ARC_String *second);
/**
* @brief check if ARC_String and cstring match
*
* @param string ARC_string to check
* @param cstring cstring to check
* @param length length of cstring
*
* @return 1 if match, 0 if they don't match
*/
uint8_t ARC_String_EqualsCString(ARC_String *string, const char *cstring, uint64_t length);
/**
* @brief check if ARC_String and cstring match
*
* @param string ARC_string to check
* @param offset postion based on string to start comparing against cstring
* @param cstring cstring to check
* @param length length of cstring
*
* @return 1 if match, 0 if they don't match
*/
uint8_t ARC_String_SubstringEqualsCString(ARC_String *string, uint64_t offset, const char *cstring, uint64_t length);
/**
* @brief checks if string is alphabetic
*
* @param string string to check
*
* @return 1 if alphabetic, 0 if not alphabetic
*/
uint8_t ARC_String_Alpha(ARC_String *string);
/**
* @brief converst substring from string to uint64_t
*
* @param string string to convert to uint64_t
*
* @return uint64_t converted number
*/
uint64_t ARC_String_ToUint64_t(ARC_String *string);
/**
* @brief converst substring from string to int64_t
*
* @param string string to convert to int64_t
*
* @return int64_t converted number
*/
int64_t ARC_String_ToInt64_t(ARC_String *string);
/**
* @brief converst substring from string to double
*
* @param string string to convert to double
*
* @return double converted number
*/
double ARC_String_ToDouble(ARC_String *string);
/**
* @brief takes a given string, and assigns index and length for position of first matching substring
*
* @param string the string that will be searched
* @param substr substring to find within string
*
* @return ~(uint64_t)0 on error, anything else on success
*/
uint64_t ARC_String_Find(ARC_String *string, ARC_String *substring);
/**
* @brief takes given cstring and gives position of first matching
*
* @param string the string that will be searched
* @param cstring the cstring to find within string
* @param length the length of cstring
*
* @return ~(uint64_t)0 on error, anything else on success
*/
uint64_t ARC_String_FindCString(ARC_String *string, const char *cstring, uint64_t length);
/**
* @brief takes a given string, and assigns index and length for position of last matching substring
*
* @param string the string that will be searched
* @param substr substring to find within string
*
* @return ~(uint64_t)0 on error, anything else on success
*/
uint64_t ARC_String_FindBack(ARC_String *string, ARC_String *substring);
/**
* @brief strips the ends based on a given char
*
* @param stripped where to store the string which has witespace stripped
* will be null if there is an error
* @param original the string which whill have the matching char stripped from
* @param charToStrip the char that will be stripped from the ends
*/
void ARC_String_StripEnds(ARC_String **stripped, ARC_String *original, char charToStrip);
/**
* @brief strips whitespace from a ARC_String
*
* @param stripped where to store the string which has witespace stripped
* will be null if there is an error
* @param original the string which whill have whitespace stripped from
*/
void ARC_String_StripWhitespace(ARC_String **stripped, ARC_String *original);
/**
* @brief strips the whitespace from the ends of a string
*
* @param stripped where to store the string which has witespace stripped from the ends
* will be null if there is an error
* @param original the string which whill have the whitespace stripped from its ends
*/
void ARC_String_StripEndsWhitespace(ARC_String **stripped, ARC_String *original);
/**
* @brief merges two strings together
*
* @param combined new ARC_String of combined strings frist + second
* @param first first part of string to combine
* @param second second part of string to combine
*/
void ARC_String_Merge(ARC_String **combined, ARC_String *first, ARC_String *second);
/**
* @brief copy a subtring from a givin ARC_String
*
* @param newString new string without specified section, will be NULL on error
* @param original string to remove section from
* @param removeIndex starting index in relation on original of what is to be removed
* @param removeLength length of section that is being removed
*/
void ARC_String_RemoveSection(ARC_String **newString, ARC_String *original, uint64_t removeIndex, uint64_t removeLength);
#ifdef __cplusplus
}
#endif
#endif //ARC_STD_STRING_H_