PPL Logo

libs/ck-libs/metis/GKlib/string.c File Reference

Functions for manipulating strings. More...

Go to the source code of this file.

Functions

char * gk_strchr_replace (char *str, char *fromlist, char *tolist)
 Replaces certain characters in a string.
int gk_strstr_replace (char *str, char *pattern, char *replacement, char *options, char **new_str)
 Regex-based search-and-replace function.
char * gk_strtprune (char *str, char *rmlist)
 Prunes characters from the end of the string.
char * gk_strhprune (char *str, char *rmlist)
 Prunes characters from the beginning of the string.
char * gk_strtoupper (char *str)
 Converts a string to upper case.
char * gk_strtolower (char *str)
 Converts a string to lower case.
char * gk_strdup (char *orgstr)
 Duplicates a string.
int gk_strcasecmp (char *s1, char *s2)
 Case insensitive string comparison.
int gk_strrcmp (char *s1, char *s2)
 Compare two strings in revere order.
char * gk_time2str (time_t time)
 Converts a time_t time into a string.
time_t gk_str2time (char *str)
 Converts a date/time string into its equivalent time_t value.
int gk_GetStringID (gk_StringMap_t *strmap, char *key)


Detailed Description

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).

Date:
Started 11/1/99
Author:
George
Version:
Id
string.c 10711 2011-08-31 22:23:04Z karypis

Definition in file string.c.


Function Documentation

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.

Parameters:
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 .
Returns:
A pointer to str itself.

Definition at line 40 of file string.c.

References gk_idx_t, and len.

Referenced by ReadTPwgts().

Here is the caller graph for this function:

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.

Parameters:
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.
Returns:
If successful, it returns 1 + the number of substitutions that were performed. Thus, if no substitutions were performed, the returned value will be 1. Otherwise it returns 0. In case of error, a meaningful error message is returned in newstr, which also needs to be freed afterwards.

Definition at line 97 of file string.c.

References gk_free(), gk_idx_t, gk_realloc(), gk_strdup(), int, len, offset, REG_ESPACE, REG_NOMATCH, regcomp(), regerror(), regexec(), regfree(), regmatch_t::rm_eo, and regmatch_t::rm_so.

Referenced by test_strstr_replace().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
str is the string that will be trimmed.
rmlist contains the set of characters that will be removed.
Returns:
A pointer to str itself.
See also:
gk_strhprune()

Definition at line 257 of file string.c.

References gk_idx_t, and len.

Referenced by gk_readfile(), and main().

Here is the caller graph for this function:

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.

Parameters:
str is the string that will be trimmed.
rmlist contains the set of characters that will be removed.
Returns:
A pointer to str itself.
See also:
gk_strtprune()

Definition at line 294 of file string.c.

References gk_idx_t, and len.

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.

Parameters:
str is the string whose case will be changed.
Returns:
A pointer to str itself.
See also:
gk_strtolower()

Definition at line 331 of file string.c.

Referenced by gk_seq_ReadGKMODPSSM().

Here is the caller graph for this function:

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.

Parameters:
str is the string whose case will be changed.
Returns:
A pointer to str itself.
See also:
gk_strtoupper()

Definition at line 351 of file string.c.

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():

  • uses the dynamic memory allocation routines of GKlib.
  • it correctly handles NULL input strings.

The string that is returned must be freed by gk_free().

Parameters:
orgstr is the string that will be duplicated.
Returns:
A pointer to the newly created string.
See also:
gk_free()

Definition at line 375 of file string.c.

References gk_malloc(), and len.

Referenced by getpathname(), gk_getbasename(), gk_getextname(), gk_getfilename(), gk_readfile(), gk_readpdbfile(), gk_strstr_replace(), gk_strtokenize(), main(), parse_cmdline(), and test_skvsort().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Warning:
This function is not equivalent to a case-insensitive strcmp() function, as it does not return ordering information.
Todo:
Remove the above warning.
Parameters:
s1 is the first string to be compared.
s2 is the second string to be compared.
Return values:
1 if the strings are identical,
0 otherwise.

Definition at line 408 of file string.c.

Referenced by gk_GetStringID().

Here is the caller graph for this function:

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.

Parameters:
s1 is the first string to be compared.
s2 is the second string to be compared.
Return values:
-1,0,1,if the s1 < s2, s1 == s2, or s1 > s2.

Definition at line 436 of file string.c.

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.

Parameters:
time is the time to be converted.
Returns:
It returns a pointer to a statically allocated string that is over-written in successive calls of this function. If the conversion failed, it returns NULL.

Definition at line 473 of file string.c.

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.

Parameters:
str is the date/time string to be converted.
Returns:
If the conversion was successful it returns the time, otherwise it returns -1.

Definition at line 504 of file string.c.

int gk_GetStringID ( gk_StringMap_t strmap,
char *  key 
)

Definition at line 524 of file string.c.

References gk_strcasecmp(), gk_StringMap_t::id, name, and gk_StringMap_t::name.

Referenced by parse_cmdline().

Here is the call graph for this function:

Here is the caller graph for this function:


Generated on Mon Sep 21 08:09:09 2020 for Charm++ by  doxygen 1.5.5