Functions for manipulating strings. More...
#include <GKlib.h>
Go to the source code of this file.
Functions | |
int | gk_GetStringID (gk_StringMap_t *strmap, char *key) |
time_t | gk_str2time (char *str) |
Converts a date/time string into its equivalent time_t value. More... | |
int | gk_strcasecmp (char *s1, char *s2) |
Case insensitive string comparison. More... | |
char * | gk_strchr_replace (char *str, char *fromlist, char *tolist) |
Replaces certain characters in a string. More... | |
char * | gk_strdup (char *orgstr) |
Duplicates a string. More... | |
char * | gk_strhprune (char *str, char *rmlist) |
Prunes characters from the beginning of the string. More... | |
int | gk_strrcmp (char *s1, char *s2) |
Compare two strings in revere order. More... | |
int | gk_strstr_replace (char *str, char *pattern, char *replacement, char *options, char **new_str) |
Regex-based search-and-replace function. More... | |
char * | gk_strtolower (char *str) |
Converts a string to lower case. More... | |
char * | gk_strtoupper (char *str) |
Converts a string to upper case. More... | |
char * | gk_strtprune (char *str, char *rmlist) |
Prunes characters from the end of the string. More... | |
char * | gk_time2str (time_t time) |
Converts a time_t time into a string. More... | |
Functions for manipulating strings.
Various functions for manipulating strings. Some of these functions provide new functionality, whereas others are drop-in replacements of standard functions (but with enhanced functionality).
Definition in file string.c.
int gk_GetStringID | ( | gk_StringMap_t * | strmap, |
char * | key | ||
) |
time_t gk_str2time | ( | char * | str | ) |
Converts a date/time string into its equivalent time_t value.
This function takes date and/or time specification and converts it in the equivalent time_t representation. The conversion is done using the strptime() function. The format that gk_str2time() understands is mm/dd/yyyy hh:mm:ss, in which the hours are in military time.
str | is the date/time string to be converted. |
int gk_strcasecmp | ( | char * | s1, |
char * | s2 | ||
) |
Case insensitive string comparison.
This function compares two strings for equality by ignoring the case of the strings.
s1 | is the first string to be compared. |
s2 | is the second string to be compared. |
1 | if the strings are identical, |
0 | otherwise. |
char* gk_strchr_replace | ( | char * | str, |
char * | fromlist, | ||
char * | tolist | ||
) |
Replaces certain characters in a string.
This function takes a string and replaces all the characters in the fromlist
with the corresponding characters from the tolist
. That is, each occurence of fromlist[i]
is replaced by tolist[i]
. If the tolist
is shorter than fromlist
, then the corresponding characters are deleted. The modifications on str
are done in place. It tries to provide a functionality similar to Perl's tr// function.
str | is the string whose characters will be replaced. |
fromlist | is the set of characters to be replaced. |
tolist | is the set of replacement characters . |
str
itself. char* gk_strdup | ( | char * | orgstr | ) |
Duplicates a string.
This function is a replacement for C's standard strdup() function. The key differences between the two are that gk_strdup():
The string that is returned must be freed by gk_free().
orgstr | is the string that will be duplicated. |
char* gk_strhprune | ( | char * | str, |
char * | rmlist | ||
) |
Prunes characters from the beginning of the string.
This function removes any starting characters that are included in the rmlist
. The trimming stops at the first character that is not in rmlist
. This function can be used to removed leading spaces, tabs, etc. This is a distructive operation as it modifies the string.
str | is the string that will be trimmed. |
rmlist | contains the set of characters that will be removed. |
str
itself. int gk_strrcmp | ( | char * | s1, |
char * | s2 | ||
) |
Compare two strings in revere order.
This function is similar to strcmp but it performs the comparison as if the two strings were reversed.
s1 | is the first string to be compared. |
s2 | is the second string to be compared. |
-1,0,1,if | the s1 < s2, s1 == s2, or s1 > s2. |
int gk_strstr_replace | ( | char * | str, |
char * | pattern, | ||
char * | replacement, | ||
char * | options, | ||
char ** | new_str | ||
) |
Regex-based search-and-replace function.
This function is a C implementation of Perl's s//
regular-expression based substitution function.
str | is the input string on which the operation will be performed. |
pattern | is the regular expression for the pattern to be matched for substitution. |
replacement | is the replacement string, in which the possible captured pattern substrings are referred to as $1, $2, ..., $9. The entire matched pattern is refered to as $0. |
options | is a string specified options for the substitution operation. Currently the "i" (case insensitive) and "g" (global substitution) are supported. |
new_str | is a reference to a pointer that will store a pointer to the newly created string that results from the substitutions. This string is allocated via gk_malloc() and needs to be freed using gk_free(). The string is returned even if no substitutions were performed. |
newstr
, which also needs to be freed afterwards. char* gk_strtolower | ( | char * | str | ) |
Converts a string to lower case.
This function converts a string to lower case. This operation modifies the string itself.
str | is the string whose case will be changed. |
str
itself. char* gk_strtoupper | ( | char * | str | ) |
Converts a string to upper case.
This function converts a string to upper case. This operation modifies the string itself.
str | is the string whose case will be changed. |
str
itself. char* gk_strtprune | ( | char * | str, |
char * | rmlist | ||
) |
Prunes characters from the end of the string.
This function removes any trailing characters that are included in the rmlist
. The trimming stops at the last character (i.e., first character from the end) that is not in rmlist
. This function can be used to removed trailing spaces, newlines, etc. This is a distructive operation as it modifies the string.
str | is the string that will be trimmed. |
rmlist | contains the set of characters that will be removed. |
str
itself. char* gk_time2str | ( | time_t | time | ) |
Converts a time_t time into a string.
This function takes a time_t-specified time and returns a string-formated representation of the corresponding time. The format of the string is mm/dd/yyyy hh:mm:ss, in which the hours are in military time.
time | is the time to be converted. |