Gromacs  2020.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions | Variables
cstringutil.h File Reference
#include <stdio.h>
#include "gromacs/utility/basedefinitions.h"
+ Include dependency graph for cstringutil.h:

Description

Generic C string handling functions.

Macros

#define CONTINUE   '\\'
 Continuation character. More...
 
#define STRLEN   4096
 Standard size for char* string buffers. More...
 
#define GMX_NO_WCMATCH   1
 Return value for gmx_wcmatch() when there is no match. More...
 
#define STEPSTRSIZE   22
 Minimum size of buffer to pass to gmx_step_str(). More...
 

Functions

int continuing (char *s)
 Strip trailing spaces and if s ends with a CONTINUE remove that too. More...
 
char * fgets2 (char *s, int n, FILE *stream)
 Reads a line from a stream. More...
 
void strip_comment (char *line)
 Remove portion of a line after a ';' comment sign. More...
 
void upstring (char *str)
 Make a string uppercase. More...
 
void ltrim (char *str)
 Remove leading whitespace from a string. More...
 
void rtrim (char *str)
 Remove trailing whitespace from a string. More...
 
void trim (char *str)
 Remove leading and trailing whitespace from a string. More...
 
int gmx_strcasecmp_min (const char *str1, const char *str2)
 Version of gmx_strcasecmp() that also ignores '-' and '_'. More...
 
int gmx_strncasecmp_min (const char *str1, const char *str2, int n)
 Version of gmx_strncasecmp() that also ignores '-' and '_'. More...
 
int gmx_strcasecmp (const char *str1, const char *str2)
 Case-insensitive strcmp(). More...
 
int gmx_strncasecmp (const char *str1, const char *str2, int n)
 Case-insensitive strncmp(). More...
 
char * gmx_strdup (const char *src)
 Creates a duplicate of src. More...
 
char * gmx_strndup (const char *src, int n)
 Duplicates first n characters of src. More...
 
int gmx_wcmatch (const char *pattern, const char *str)
 Pattern matching with wildcards. More...
 
unsigned int gmx_string_fullhash_func (const char *s, unsigned int hash_init)
 Return a hash of the string according to Dan J. Bernsteins algorithm. More...
 
unsigned int gmx_string_hash_func (const char *s, unsigned int hash_init)
 Return a hash of the string according to Dan J. Bernsteins algorithm. More...
 
char * wrap_lines (const char *buf, int line_width, int indent, gmx_bool bIndentFirst)
 Wraps lines, optionally indenting lines. More...
 
int64_t str_to_int64_t (const char *str, char **endptr)
 Convert a string to int64_t. More...
 
char * gmx_step_str (int64_t i, char *buf)
 Prints a int64_t value in buf and returns the pointer to buf. More...
 

Variables

const unsigned int gmx_string_hash_init
 Magic hash initialization number from Dan J. More...
 

Macro Definition Documentation

#define CONTINUE   '\\'

Continuation character.

#define GMX_NO_WCMATCH   1

Return value for gmx_wcmatch() when there is no match.

#define STEPSTRSIZE   22

Minimum size of buffer to pass to gmx_step_str().

#define STRLEN   4096

Standard size for char* string buffers.

Function Documentation

int continuing ( char *  s)

Strip trailing spaces and if s ends with a CONTINUE remove that too.

Returns
TRUE if s ends with a CONTINUE, FALSE otherwise.
char* fgets2 ( char *  s,
int  n,
FILE *  stream 
)

Reads a line from a stream.

This routine reads a string from stream of max length n, including \0 and zero terminated, without newlines. s should be long enough (>= n)

char* gmx_step_str ( int64_t  i,
char *  buf 
)

Prints a int64_t value in buf and returns the pointer to buf.

buf should be large enough to contain i: STEPSTRSIZE (22) chars. When multiple int64_t values are printed in the same printf call, be sure to call gmx_step_str with different buffers.

int gmx_strcasecmp ( const char *  str1,
const char *  str2 
)

Case-insensitive strcmp().

int gmx_strcasecmp_min ( const char *  str1,
const char *  str2 
)

Version of gmx_strcasecmp() that also ignores '-' and '_'.

char* gmx_strdup ( const char *  src)

Creates a duplicate of src.

unsigned int gmx_string_fullhash_func ( const char *  s,
unsigned int  hash_init 
)

Return a hash of the string according to Dan J. Bernsteins algorithm.

Parameters
[in]sString to calculate hash for.
[in]hash_initInitial (or previous) hash value.
Returns
Updated hash value (hash_init combined with string hash).

On the first invocation for a new string, use the constant gmx_string_hash_init for the second argument. If you want to create a hash corresponding to several concatenated strings, provide the returned hash value as hash_init for the second string, etc.

unsigned int gmx_string_hash_func ( const char *  s,
unsigned int  hash_init 
)

Return a hash of the string according to Dan J. Bernsteins algorithm.

Parameters
[in]sString to calculate hash for.
[in]hash_initInitial (or previous) hash value.
Returns
Updated hash value (hash_init combined with string hash).

Identical to gmx_string_fullhash_func, except that this routine only uses characters for which isalnum(c) is true, and all characters are converted to upper case.

int gmx_strncasecmp ( const char *  str1,
const char *  str2,
int  n 
)

Case-insensitive strncmp().

int gmx_strncasecmp_min ( const char *  str1,
const char *  str2,
int  n 
)

Version of gmx_strncasecmp() that also ignores '-' and '_'.

char* gmx_strndup ( const char *  src,
int  n 
)

Duplicates first n characters of src.

int gmx_wcmatch ( const char *  pattern,
const char *  str 
)

Pattern matching with wildcards.

Parameters
[in]patternPattern to match against.
[in]strString to match.
Returns
0 on match, GMX_NO_WCMATCH if there is no match.

Matches str against pattern, which may contain * and ? wildcards. All other characters are matched literally. Currently, it is not possible to match literal * or ?.

void ltrim ( char *  str)

Remove leading whitespace from a string.

void rtrim ( char *  str)

Remove trailing whitespace from a string.

int64_t str_to_int64_t ( const char *  str,
char **  endptr 
)

Convert a string to int64_t.

This method works as the standard library function strtol(), except that it does not support different bases.

void strip_comment ( char *  line)

Remove portion of a line after a ';' comment sign.

void trim ( char *  str)

Remove leading and trailing whitespace from a string.

void upstring ( char *  str)

Make a string uppercase.

char* wrap_lines ( const char *  buf,
int  line_width,
int  indent,
gmx_bool  bIndentFirst 
)

Wraps lines, optionally indenting lines.

Wraps lines at linewidth, indenting all following lines by indent spaces. A temp buffer is allocated and returned, which can be disposed of if no longer needed. If bIndentFirst is FALSE, then the first line will not be indented, only the lines that are created due to wapping.

Variable Documentation

const unsigned int gmx_string_hash_init

Magic hash initialization number from Dan J.

Bernstein.