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
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2016 The Earlham Institute
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 
26 #ifndef STRING_UTILS_H
27 #define STRING_UTILS_H
28 
29 #include <stdio.h>
30 
31 #include "typedefs.h"
33 #include "linked_list.h"
34 
35 
36 #ifdef __cplusplus
37  extern "C" {
38 #endif
39 
40 
53 GRASSROOTS_UTIL_API char *CopyToNewString (const char * const src_p, const size_t length_to_copy, bool trim);
54 
55 
66 GRASSROOTS_UTIL_API char *EasyCopyToNewString (const char * const src_s);
67 
68 
76 GRASSROOTS_UTIL_API void FreeCopiedString (char *str_p);
77 
78 
88 GRASSROOTS_UTIL_API bool GetLineFromFile (FILE *in_f, char **buffer_pp);
89 
90 
97 GRASSROOTS_UTIL_API void FreeLineBuffer (char *buffer_p);
98 
99 
111 GRASSROOTS_UTIL_API bool CloneValidString (const char *src_s, char **dest_ss);
112 
113 
127 GRASSROOTS_UTIL_API LinkedList *ParseStringToStringLinkedList (const char * const format_p, const char * const delimiters_p, const bool treat_whitespace_as_delimiter_flag);
128 
129 
130 
143 GRASSROOTS_UTIL_API LinkedList *ParseStringToIntLinkedList (const char * const format_p, const char * const delimiters_p);
144 
145 
158 GRASSROOTS_UTIL_API LinkedList *ParseStringToDataLinkedList (const char * const format_p, const char * const delimiters_p);
159 
160 
169 GRASSROOTS_UTIL_API char *ConcatenateStrings (const char * const first_s, const char * const second_s);
170 
171 
180 GRASSROOTS_UTIL_API void ReplaceCharacter (char *value_s, const char char_to_replace, const char replacement_char);
181 
182 
183 
184 GRASSROOTS_UTIL_API bool SearchAndReplaceInString (const char *src_s, char **dest_ss, const char *to_replace_s, const char *with_s);
185 
186 
200 GRASSROOTS_UTIL_API bool GetKeyValuePair (char *line_p, char **key_pp, char **value_pp, const char comment_identifier);
201 
202 
216 GRASSROOTS_UTIL_API char *GetNextToken (const char **start_pp, const char *delimiters_p, const bool check_for_whitespace_flag, const bool update_position_flag);
217 
225 GRASSROOTS_UTIL_API void FreeToken (char *token_s);
226 
227 
238 GRASSROOTS_UTIL_API void NullifyTrailingZeroes (char *numeric_string_p);
239 
240 
248 GRASSROOTS_UTIL_API bool IsStringEmpty (const char *value_s);
249 
250 
262 GRASSROOTS_UTIL_API int Stricmp (const char *c0_s, const char *c1_s);
263 
264 
277 GRASSROOTS_UTIL_API int Strnicmp (const char *c0_s, const char *c1_s, size_t length);
278 
279 
290 GRASSROOTS_UTIL_API const char *Stristr (const char *value_s, const char *substring_s);
291 
292 
293 
303 GRASSROOTS_UTIL_API char *Strrstr (const char *haystack_s, const char *needle_s);
304 
305 
306 
319 GRASSROOTS_UTIL_API bool ReplaceStringValue (char **dest_ss, const char * const src_s);
320 
321 
330 GRASSROOTS_UTIL_API void ReplaceChars (char *value_s, char old_data, char new_data);
331 
332 
340 GRASSROOTS_UTIL_API uint32 HashString (const void * const key_p);
341 
342 
354 GRASSROOTS_UTIL_API char *GetFileContentsAsString (FILE *input_f);
355 
356 
368 GRASSROOTS_UTIL_API char *GetFileContentsAsStringByFilename (const char *filename_s);
369 
379 GRASSROOTS_UTIL_API char *ConcatenateVarargsStrings (const char *value_s, ...);
380 
381 
382 
383 
384 
385 
393 GRASSROOTS_UTIL_API bool DoesStringContainWhitespace (const char *value_s);
394 
395 
396 GRASSROOTS_UTIL_API bool DoesStringEndWith (const char *value_s, const char *ending_s);
397 
398 
399 GRASSROOTS_UTIL_API bool DoesStringStartWith (const char *value_s, const char *start_s);
400 
401 
402 GRASSROOTS_UTIL_API char *GetStringAsLowerCase (const char *value_s);
403 
404 
405 GRASSROOTS_UTIL_API void FreeStringArray (char **values_ss, const size_t num_values);
406 
407 
408 GRASSROOTS_UTIL_API bool DoStringsMatch (const char * const val_0_s, const char * const val_1_s);
409 
410 
411 GRASSROOTS_UTIL_API bool CopyAndAddStringValue (const char * const src_s, char **dest_ss);
412 
413 
414 GRASSROOTS_UTIL_API char *RemoveStartingAndTrailingWhitespace (const char *value_s);
415 
416 
417 #ifdef __cplusplus
418 }
419 #endif
420 
421 
422 
423 
424 
425 #endif /* #ifndef STRING_UTILS_H */
426 
ConcatenateVarargsStrings
char * ConcatenateVarargsStrings(const char *value_s,...)
Concatenate a va_list of strings.
GetLineFromFile
bool GetLineFromFile(FILE *in_f, char **buffer_pp)
Read a line from a file with no buffer overflow issues.
ReplaceChars
void ReplaceChars(char *value_s, char old_data, char new_data)
Replace each instance of a character within a string with another.
ParseStringToIntLinkedList
LinkedList * ParseStringToIntLinkedList(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...
grassroots_util_library.h
ParseStringToDataLinkedList
LinkedList * ParseStringToDataLinkedList(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...
GetNextToken
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.
Strnicmp
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.
NullifyTrailingZeroes
void NullifyTrailingZeroes(char *numeric_string_p)
Format a string containing a number by removing all of its trailing zeroes, e.g.
GetFileContentsAsStringByFilename
char * GetFileContentsAsStringByFilename(const char *filename_s)
Get the contents of FILE as c-style string.
Stricmp
int Stricmp(const char *c0_s, const char *c1_s)
Do a case-insensitive comparison between two strings.
FreeCopiedString
void FreeCopiedString(char *str_p)
Delete a string previously allocated using CopyToNewString.
SearchAndReplaceInString
bool SearchAndReplaceInString(const char *src_s, char **dest_ss, const char *to_replace_s, const char *with_s)
GetKeyValuePair
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.
IsStringEmpty
bool IsStringEmpty(const char *value_s)
Test whether a string is NULL or contains just whitespace.
CloneValidString
bool CloneValidString(const char *src_s, char **dest_ss)
Clone a valid string to a destination string pointer.
DoesStringContainWhitespace
bool DoesStringContainWhitespace(const char *value_s)
Test whether a given string contains any whitespace characters.
Stristr
const char * Stristr(const char *value_s, const char *substring_s)
Find a substring within a string.
Strrstr
char * Strrstr(const char *haystack_s, const char *needle_s)
Find the last occurence of a substring within a string.
typedefs.h
GetFileContentsAsString
char * GetFileContentsAsString(FILE *input_f)
Get the contents of FILE as c-style string.
FreeToken
void FreeToken(char *token_s)
Free a c-style string that has been returned by GetNextToken.
LinkedList
A doubly-linked list that can be traversed in either direction.
Definition: linked_list.h:56
CopyToNewString
char * CopyToNewString(const char *const src_p, const size_t length_to_copy, bool trim)
Copy a string to a newly created string.
FreeStringArray
void FreeStringArray(char **values_ss, const size_t num_values)
ReplaceStringValue
bool ReplaceStringValue(char **dest_ss, const char *const src_s)
Make a copy of a string.
DoesStringStartWith
bool DoesStringStartWith(const char *value_s, const char *start_s)
GetStringAsLowerCase
char * GetStringAsLowerCase(const char *value_s)
ConcatenateStrings
char * ConcatenateStrings(const char *const first_s, const char *const second_s)
Get a newly created string that is the concatenation of two others.
linked_list.h
A doubly-linked list.
DoesStringEndWith
bool DoesStringEndWith(const char *value_s, const char *ending_s)
ParseStringToStringLinkedList
LinkedList * ParseStringToStringLinkedList(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.
ReplaceCharacter
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.
HashString
uint32 HashString(const void *const key_p)
Create a numeric value for suitable for hashing from a given string.
CopyAndAddStringValue
bool CopyAndAddStringValue(const char *const src_s, char **dest_ss)
FreeLineBuffer
void FreeLineBuffer(char *buffer_p)
Free a buffer that has been allocated with GetLineFromFile.
RemoveStartingAndTrailingWhitespace
char * RemoveStartingAndTrailingWhitespace(const char *value_s)
DoStringsMatch
bool DoStringsMatch(const char *const val_0_s, const char *const val_1_s)
GRASSROOTS_UTIL_API
#define GRASSROOTS_UTIL_API
Definition: grassroots_util_library.h:47
EasyCopyToNewString
char * EasyCopyToNewString(const char *const src_s)
Copy a string to a newly created string.