replacemnt functions in string, should be memory safe
This commit is contained in:
parent
4d7ba1cf4e
commit
19d6120871
2 changed files with 203 additions and 24 deletions
|
|
@ -6,6 +6,7 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "bool.h"
|
||||
|
||||
/**
|
||||
* @brief substring position within a string
|
||||
|
|
@ -72,9 +73,9 @@ void ARC_String_RemoveSubstring(ARC_String **newString, ARC_String *original, AR
|
|||
* @param first string to check against second
|
||||
* @param second string to check against first
|
||||
*
|
||||
* @return 1 if match, 0 if they don't match
|
||||
* @return ARC_True if match, ARC_False if they don't match
|
||||
*/
|
||||
uint8_t ARC_String_Equals(ARC_String *first, ARC_String *second);
|
||||
ARC_Bool ARC_String_Equals(ARC_String *first, ARC_String *second);
|
||||
|
||||
/**
|
||||
* @brief check if ARC_String and cstring match
|
||||
|
|
@ -83,9 +84,9 @@ uint8_t ARC_String_Equals(ARC_String *first, ARC_String *second);
|
|||
* @param cstring cstring to check
|
||||
* @param length length of cstring
|
||||
*
|
||||
* @return 1 if match, 0 if they don't match
|
||||
* @return ARC_True if match, ARC_False if they don't match
|
||||
*/
|
||||
uint8_t ARC_String_EqualsCString(ARC_String *string, const char *cstring, uint64_t length);
|
||||
ARC_Bool ARC_String_EqualsCString(ARC_String *string, const char *cstring, uint64_t length);
|
||||
|
||||
/**
|
||||
* @brief check if ARC_String and cstring match
|
||||
|
|
@ -95,9 +96,20 @@ uint8_t ARC_String_EqualsCString(ARC_String *string, const char *cstring, uint64
|
|||
* @param string ARC_string to check
|
||||
* @param cstring cstring to check
|
||||
*
|
||||
* @return 1 if match, 0 if they don't match
|
||||
* @return ARC_True if match, ARC_False if they don't match
|
||||
*/
|
||||
uint8_t ARC_String_EqualsCStringWithStrlen(ARC_String *string, const char *cstring);
|
||||
ARC_Bool ARC_String_EqualsCStringWithStrlen(ARC_String *string, const char *cstring);
|
||||
|
||||
/**
|
||||
* @brief check if substring of first equals second string
|
||||
*
|
||||
* @param first string to check against second
|
||||
* @param offset postion based on first to start comparing against second
|
||||
* @param second string to check against first
|
||||
*
|
||||
* @return ARC_True if match, ARC_False if they don't match
|
||||
*/
|
||||
ARC_Bool ARC_String_SubstringEquals(ARC_String *first, uint64_t offset, ARC_String *second);
|
||||
|
||||
/**
|
||||
* @brief check if ARC_String and cstring match
|
||||
|
|
@ -107,9 +119,9 @@ uint8_t ARC_String_EqualsCStringWithStrlen(ARC_String *string, const char *cstri
|
|||
* @param cstring cstring to check
|
||||
* @param length length of cstring
|
||||
*
|
||||
* @return 1 if match, 0 if they don't match
|
||||
* @return ARC_True if match, ARC_False if they don't match
|
||||
*/
|
||||
uint8_t ARC_String_SubstringEqualsCString(ARC_String *string, uint64_t offset, const char *cstring, uint64_t length);
|
||||
ARC_Bool ARC_String_SubstringEqualsCString(ARC_String *string, uint64_t offset, const char *cstring, uint64_t length);
|
||||
|
||||
/**
|
||||
* @brief checks if string is alphabetic
|
||||
|
|
@ -260,6 +272,52 @@ void ARC_String_Merge(ARC_String **combined, ARC_String *first, ARC_String *seco
|
|||
*/
|
||||
void ARC_String_RemoveSection(ARC_String **newString, ARC_String *original, uint64_t removeIndex, uint64_t removeLength);
|
||||
|
||||
/**
|
||||
* @brief replaces characters in string matching the given pattern
|
||||
*
|
||||
* @note this uses ARC_String_CopyReplaceMatching, so debug logs will be thrown in that function not this one
|
||||
*
|
||||
* @param string the string that will be modified, will discard changes and set arc_errno on fail
|
||||
* @param pattern the pattern to replace in the string on match
|
||||
* @param replacement the string that will replace the matched pattern
|
||||
*/
|
||||
void ARC_String_ReplaceMatching(ARC_String **string, ARC_String *pattern, ARC_String *replacement);
|
||||
|
||||
/**
|
||||
* @brief replaces characters in a copy of a string matching the given pattern
|
||||
*
|
||||
* @note original will not be modified
|
||||
* @note newString will need to be destroyed if it is not set to NULL
|
||||
*
|
||||
* @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
|
||||
* @param original the original string that will be copied
|
||||
* @param pattern the pattern to replace in the string on match
|
||||
* @param replacement the string that will replace the matched pattern
|
||||
*/
|
||||
void ARC_String_CopyReplaceMatching(ARC_String **newString, ARC_String *original, ARC_String *pattern, ARC_String *replacement);
|
||||
|
||||
/**
|
||||
* @brief replaces characters in string matching the given pattern
|
||||
*
|
||||
* @param string the string that will be modified, will discard changes and set arc_errno on fail
|
||||
* @param patternCString the cstring pattern to replace in the string on match
|
||||
* @param patternLength the lenght of the cstring pattern
|
||||
* @param replacementCstring the cstring that will replace the matched pattern
|
||||
* @param replacementLength the length of the cstring replacement
|
||||
*/
|
||||
void ARC_String_ReplaceMatchingCString(ARC_String **string, char *patternCString, uint64_t patternLength, char *replacementCString, uint64_t replacementLength);
|
||||
|
||||
/**
|
||||
* @brief replaces characters in string matching the given pattern
|
||||
*
|
||||
* @note this uses ARC_String_ReplaceMatchingCString, so debug logs will be thrown in that function not this one
|
||||
*
|
||||
* @param string the string that will be modified, will discard changes and set arc_errno on fail
|
||||
* @param patternCString the cstring pattern to replace in the string on match
|
||||
* @param replacementCstring the cstring that will replace the matched pattern
|
||||
*/
|
||||
void ARC_String_ReplaceMatchingCStringWithStrlen(ARC_String **string, char *patternCString, char *replacement);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue