GenSVM
Functions
gensvm_strutil.h File Reference

Header file for gensvm_strutil.c. More...

#include "gensvm_globals.h"
Include dependency graph for gensvm_strutil.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool str_startswith (const char *str, const char *pre)
 Check if a string starts with a prefix. More...
 
bool str_endswith (const char *str, const char *suf)
 Check if a string ends with a suffix. More...
 
bool str_contains_char (const char *str, const char c)
 Check if a string contains a char. More...
 
char ** str_split (char *original, const char *delims, int *len_ret)
 Split a string on delimiters and return an array of parts. More...
 
void next_line (FILE *fid, char *filename)
 Move to next line in file. More...
 
char * get_line (FILE *fid, char *filename, char *buffer)
 Read line to buffer. More...
 
double get_fmt_double (FILE *fid, char *filename, const char *fmt)
 Read a double from file following a format. More...
 
long get_fmt_long (FILE *fid, char *filename, const char *fmt)
 Read a long integer from file following a format. More...
 
long all_doubles_str (char *buffer, long offset, double *all_doubles)
 Read all doubles in a given buffer. More...
 
long all_longs_str (char *buffer, long offset, long *all_longs)
 Read all longs in a given buffer. More...
 

Detailed Description

Header file for gensvm_strutil.c.

Author
G.J.J. van den Burg
Date
2013-08-01

Function declarations for useful string functions used in parsing input files.

This file is part of GenSVM.

GenSVM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

GenSVM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GenSVM. If not, see http://www.gnu.org/licenses/.

Definition in file gensvm_strutil.h.

Function Documentation

◆ all_doubles_str()

long all_doubles_str ( char *  buffer,
long  offset,
double *  all_doubles 
)

Read all doubles in a given buffer.

This function is used to read a line of doubles from a buffer. All the doubles found are stored in a pre-allocated array.

Parameters
[in]buffera string buffer
[in]offsetan offset of the string to start looking for doubles
[in]all_doublespre-allocated array of doubles (should be large enough)
Returns
number of doubles read

Definition at line 265 of file gensvm_strutil.c.

◆ all_longs_str()

long all_longs_str ( char *  buffer,
long  offset,
long *  all_longs 
)

Read all longs in a given buffer.

This function is used to read a line of longs from a buffer. All the longs found are stored in a pre-allocated array.

Parameters
[in]buffera string buffer
[in]offsetan offset of the string to start looking for longs
[in]all_longspre-allocated array of longs (should be large enough)
Returns
number of longs read

Definition at line 301 of file gensvm_strutil.c.

◆ get_fmt_double()

double get_fmt_double ( FILE *  fid,
char *  filename,
const char *  fmt 
)

Read a double from file following a format.

This function reads a double value from a file. If no value can be found, a warning is printed to stderr, and NAN is returned.

Parameters
[in]fidFile opened for reading
[in]filenameName of the file
[in]fmtFormat containing a float format
Returns
value read (if any)

Definition at line 217 of file gensvm_strutil.c.

Here is the call graph for this function:

◆ get_fmt_long()

long get_fmt_long ( FILE *  fid,
char *  filename,
const char *  fmt 
)

Read a long integer from file following a format.

Parameters
[in]fidFile opened for reading
[in]filenameName of the file
[in]fmtFormat containing a long integer format
Returns
value read (if any)

Definition at line 238 of file gensvm_strutil.c.

Here is the call graph for this function:

◆ get_line()

char* get_line ( FILE *  fid,
char *  filename,
char *  buffer 
)

Read line to buffer.

Parameters
[in]fidFile opened for reading
[in]filenamename of the file
[in,out]bufferallocated buffer to read to

Definition at line 196 of file gensvm_strutil.c.

Here is the call graph for this function:

◆ next_line()

void next_line ( FILE *  fid,
char *  filename 
)

Move to next line in file.

Parameters
[in]fidFile opened for reading
[in]filenamename of the file pointed to by fid

Definition at line 183 of file gensvm_strutil.c.

Here is the call graph for this function:

◆ str_contains_char()

bool str_contains_char ( const char *  str,
const char  c 
)

Check if a string contains a char.

Simple utility function to check if a char occurs in a string.

Parameters
[in]strinput string
[in]ccharacter
Returns
number of times c occurs in str

Definition at line 76 of file gensvm_strutil.c.

◆ str_endswith()

bool str_endswith ( const char *  str,
const char *  suf 
)

Check if a string ends with a suffix.

Parameters
[in]strstring
[in]sufsuffix
Returns
boolean, true if string ends with suffix, false otherwise

Definition at line 57 of file gensvm_strutil.c.

◆ str_split()

char** str_split ( char *  original,
const char *  delims,
int *  len_ret 
)

Split a string on delimiters and return an array of parts.

This function takes as input a string and a string of delimiters. As output, it gives an array of the parts of the first string, splitted on the characters in the second string. The input string is not changed, and the output contains all copies of the input string parts.

Note
The code is based on: http://stackoverflow.com/a/9210560
Parameters
[in]originalstring you wish to split
[in]delimsstring with delimiters to split on
[out]len_retlength of the output array
Returns
array of string parts

Definition at line 130 of file gensvm_strutil.c.

Here is the call graph for this function:

◆ str_startswith()

bool str_startswith ( const char *  str,
const char *  pre 
)

Check if a string starts with a prefix.

Parameters
[in]strstring
[in]preprefix
Returns
boolean, true if string starts with prefix, false otherwise

Definition at line 42 of file gensvm_strutil.c.