csplit.h External Functions
csplit
CSplitError_t csplit(CSplitList_t* list, char* input_str, char* token);
Top level csplit function call. Outputs a csplit list split on a string token. Calls csplit_lim with max_splits = len(input_str), ensuring that all possible splits will be made.
Params:
[out]: list -> output list splitting input str on string token
[in]: input_str -> input string which will be split
[in]: token -> string on which to split
Returns:
err -> error code if there was a problem with csplitting.
csplit_lim
CSplitError_t csplit_lim(CSplitList_t* list, char* input_str, char* token, int max_splits);
Function that allows user to split based on a limited number of splits, either forward or in reverse. A max_splits >= len(input_str) will guarantee all possible splits
Params:
[out]: list -> output list splitting input str on string token
[in]: input_str -> input string which will be split
[in]: token -> string on which to split
[in]: max_splits -> max number of splits to perform. Negative if starting from end of string.
Returns:
err -> error code if there was a problem with csplitting.
csplit_init_list
CSplitList_t* csplit_init_list();
Function for initializing a csplit list
Params:
[in]: buff_size -> user set buffer size. Make sure this is large enough for your largest fragment
Returns:
list -> an allocated csplit list
csplit_clear_list
void csplit_clear_list(CSplitList_t* list);
Clears all memory for an allocated csplit list
Params:
[in]: list -> a previously allocated csplit list to be freed
csplit_print_list_info
void csplit_print_list_info(CSplitList_t* list, FILE* fp);
Function that prints information about a csplit list
Params:
[in]: list -> list for which to print info
[in]: fp -> file pointer to print into.
csplit_get_fragment_at_index
char* csplit_get_fragment_at_index(CSplitList_t* list, int index);
Function that returns the string fragment at a certain index in the list
Params:
[in]: list -> list generated by csplit
[in]: index -> index to search for (can be negative for getting at index from back of list)
Returns:
text -> string at the given index or NULL if index out of range.
csplit_reverse_list
CSplitError_t csplit_reverse_list(CSplitList_t* list);
Function that reverses the list generated by csplit
Params:
[out]: list -> list to reverse
Returns:
err -> error code if there is an error
csplit_strip
char* csplit_strip(char* input_str);
Function that strips a given string into an output string. Will remove whitespace character: * \n, \r, \t, space will be removed from the start and end of each string.
Params:
[in]: input_str -> the input string to strip
Returns:
output_str -> the string with whitespace removed from the ends. Must be freed.
csplit_remove_whitespace
char* csplit_remove_whitespace(char* input_str);
Function that removes all whitespace characters of a given string into an output string. * Note that resulting char* must be free'd after it is no longer used
Params:
[in]: input_str -> the input string to strip
Returns:
output_str -> the string with whitespace removed.
csplit_startswith
int csplit_startswith(char* input_str, char* starts_with);
Function that checks if a given string starts with another given string.
Params:
[in]: input_str -> string to check against
[in]: starts_with -> string to try to match with start of input string
Returns:
int -> -2 if input is invalid, -1 if doesn't start with given string, or 0 if it does
csplit_endswith
int csplit_endswith(char* input_str, char* ends_with);
Function that checks if a given string ends with another given string.
Params:
[in]: input_str -> string to check against
[in]: ends_with -> string to try to match with end of input string
Returns:
int -> -2 if input is invalid, -1 if doesn't end with given string, or 0 if it does
rcsplit
CSplitError_t rcsplit(CSplitList_t* output_list, char* input_str, char* token);
Function that runs csplit and then reverses the output.
Params:
[out]: output_list -> output list splitting input str on string token
[in]: input_str -> input string which will be split
[in]: token -> string on which to split
Returns:
err -> error code if there was a problem with csplitting.
csplit.h Internal Functions
These functions are used internally by the csplit library, and it is not recommended to use them outside of this internal context.
csplit_push_to_list
CSplitError_t csplit_push_to_list(CSplitList_t* list, CSplitFragment_t* fragment, size_t buff_size);
Function that pushes a new CSplitFragment to the end of the list, and allocates memory for the text
Params:
[out]: list -> The list with fragment appended to the tail
[in]: fragment -> fragment to append to the list. fragment->text will be allocated
csplit_rstr
CSplitError_t csplit_rstr(CSplitList_t* list, char* input_str, char* token, int max_splits);
Function that runs csplit on a particular string from the end of the input. Called if max_splits < 0
Params:
[out]: list -> split input string into this list structure
[in]: input_str -> input string
[in]: token -> character on which to split
[in]: max_splits -> maximum number of splits. If negative will split from end of string
Returns:
err -> error code if there was a problem with csplitting.
csplit_str
CSplitError_t csplit_str(CSplitList_t* list, char* input_str, char* token, int max_splits);
Function that splits a given input string based on another string.
Params:
[out]: list -> output list splitting input str on string token
[in]: input_str -> input string which will be split
[in]: token -> string on which to split
[in]: max_splits -> max number of splits to perform. Negative if starting from end of string.
Returns:
err -> error code if there was a problem with csplitting.