Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
string_utils.h File Reference

A set of string functions. More...

#include <stdio.h>
#include "typedefs.h"
#include "grassroots_util_library.h"
#include "linked_list.h"
Include dependency graph for string_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

char * CopyToNewString (const char *const src_p, const size_t length_to_copy, bool trim)
 Copy a string to a newly created string. More...
 
char * EasyCopyToNewString (const char *const src_s)
 Copy a string to a newly created string. More...
 
void FreeCopiedString (char *str_p)
 Delete a string previously allocated using CopyToNewString. More...
 
bool GetLineFromFile (FILE *in_f, char **buffer_pp)
 Read a line from a file with no buffer overflow issues. More...
 
void FreeLineBuffer (char *buffer_p)
 Free a buffer that has been allocated with GetLineFromFile. More...
 
bool CloneValidString (const char *src_s, char **dest_ss)
 Clone a valid string to a destination string pointer. More...
 
LinkedListParseStringToStringLinkedList (const char *const format_p, const char *const delimiters_p, const bool treat_whitespace_as_delimiter_flag)
 Parse the format string and sort out into a linked list of tokens. More...
 
LinkedListParseStringToIntLinkedList (const char *const format_p, const char *const delimiters_p)
 Parse the format string and sort out into a linked list of IntListNodes holding the tokens as numbers. More...
 
LinkedListParseStringToDataLinkedList (const char *const format_p, const char *const delimiters_p)
 Parse the format string and sort out into a linked list of IntListNodes holding the tokens as numbers. More...
 
char * ConcatenateStrings (const char *const first_s, const char *const second_s)
 Get a newly created string that is the concatenation of two others. More...
 
void ReplaceCharacter (char *value_s, const char char_to_replace, const char replacement_char)
 Replace all instances of a character by another within a string. More...
 
bool SearchAndReplaceInString (const char *src_s, char **dest_ss, const char *to_replace_s, const char *with_s)
 
bool GetKeyValuePair (char *line_p, char **key_pp, char **value_pp, const char comment_identifier)
 Get and make copies of two strings from a line of the format. More...
 
char * GetNextToken (const char **start_pp, const char *delimiters_p, const bool check_for_whitespace_flag, const bool update_position_flag)
 Get a copy of the next word from a buffer. More...
 
void FreeToken (char *token_s)
 Free a c-style string that has been returned by GetNextToken. More...
 
void NullifyTrailingZeroes (char *numeric_string_p)
 Format a string containing a number by removing all of its trailing zeroes, e.g. More...
 
bool IsStringEmpty (const char *value_s)
 Test whether a string is NULL or contains just whitespace. More...
 
int Stricmp (const char *c0_s, const char *c1_s)
 Do a case-insensitive comparison between two strings. More...
 
int Strnicmp (const char *c0_s, const char *c1_s, size_t length)
 Do a case-insensitive comparison between the initial portions of two strings. More...
 
const char * Stristr (const char *value_s, const char *substring_s)
 Find a substring within a string. More...
 
char * Strrstr (const char *haystack_s, const char *needle_s)
 Find the last occurence of a substring within a string. More...
 
bool ReplaceStringValue (char **dest_ss, const char *const src_s)
 Make a copy of a string. More...
 
void ReplaceChars (char *value_s, char old_data, char new_data)
 Replace each instance of a character within a string with another. More...
 
uint32 HashString (const void *const key_p)
 Create a numeric value for suitable for hashing from a given string. More...
 
char * GetFileContentsAsString (FILE *input_f)
 Get the contents of FILE as c-style string. More...
 
char * GetFileContentsAsStringByFilename (const char *filename_s)
 Get the contents of FILE as c-style string. More...
 
char * ConcatenateVarargsStrings (const char *value_s,...)
 Concatenate a va_list of strings. More...
 
bool DoesStringContainWhitespace (const char *value_s)
 Test whether a given string contains any whitespace characters. More...
 
bool DoesStringEndWith (const char *value_s, const char *ending_s)
 
bool DoesStringStartWith (const char *value_s, const char *start_s)
 
char * GetStringAsLowerCase (const char *value_s)
 
void FreeStringArray (char **values_ss, const size_t num_values)
 
bool DoStringsMatch (const char *const val_0_s, const char *const val_1_s)
 
bool CopyAndAddStringValue (const char *const src_s, char **dest_ss)
 
char * RemoveStartingAndTrailingWhitespace (const char *value_s)
 

Detailed Description

A set of string functions.

A variety of functions for manipulating strings.

Function Documentation

◆ CloneValidString()

bool CloneValidString ( const char *  src_s,
char **  dest_ss 
)

Clone a valid string to a destination string pointer.

Parameters
src_sThe string to clone. If this is NULL then the function will treat it as a valid clone.
dest_ssThe destination where the cloned string will be stored if successful. If src_s is NULL, then this will be set to NULL too.
Returns
true if the string was successfully cloned or it src_s is NULL, false otherwise.

◆ SearchAndReplaceInString()

bool SearchAndReplaceInString ( const char *  src_s,
char **  dest_ss,
const char *  to_replace_s,
const char *  with_s 
)

◆ DoesStringEndWith()

bool DoesStringEndWith ( const char *  value_s,
const char *  ending_s 
)

◆ DoesStringStartWith()

bool DoesStringStartWith ( const char *  value_s,
const char *  start_s 
)

◆ GetStringAsLowerCase()

char* GetStringAsLowerCase ( const char *  value_s)

◆ FreeStringArray()

void FreeStringArray ( char **  values_ss,
const size_t  num_values 
)

◆ DoStringsMatch()

bool DoStringsMatch ( const char *const  val_0_s,
const char *const  val_1_s 
)

◆ CopyAndAddStringValue()

bool CopyAndAddStringValue ( const char *const  src_s,
char **  dest_ss 
)

◆ RemoveStartingAndTrailingWhitespace()

char* RemoveStartingAndTrailingWhitespace ( const char *  value_s)