GenSVM
|
Header file for gensvm_strutil.c. More...
#include "gensvm_globals.h"
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... | |
Header file for gensvm_strutil.c.
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.
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.
[in] | buffer | a string buffer |
[in] | offset | an offset of the string to start looking for doubles |
[in] | all_doubles | pre-allocated array of doubles (should be large enough) |
Definition at line 265 of file gensvm_strutil.c.
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.
[in] | buffer | a string buffer |
[in] | offset | an offset of the string to start looking for longs |
[in] | all_longs | pre-allocated array of longs (should be large enough) |
Definition at line 301 of file gensvm_strutil.c.
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.
[in] | fid | File opened for reading |
[in] | filename | Name of the file |
[in] | fmt | Format containing a float format |
Definition at line 217 of file gensvm_strutil.c.
long get_fmt_long | ( | FILE * | fid, |
char * | filename, | ||
const char * | fmt | ||
) |
Read a long integer from file following a format.
[in] | fid | File opened for reading |
[in] | filename | Name of the file |
[in] | fmt | Format containing a long integer format |
Definition at line 238 of file gensvm_strutil.c.
char* get_line | ( | FILE * | fid, |
char * | filename, | ||
char * | buffer | ||
) |
Read line to buffer.
[in] | fid | File opened for reading |
[in] | filename | name of the file |
[in,out] | buffer | allocated buffer to read to |
Definition at line 196 of file gensvm_strutil.c.
void next_line | ( | FILE * | fid, |
char * | filename | ||
) |
Move to next line in file.
[in] | fid | File opened for reading |
[in] | filename | name of the file pointed to by fid |
Definition at line 183 of file gensvm_strutil.c.
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.
[in] | str | input string |
[in] | c | character |
Definition at line 76 of file gensvm_strutil.c.
bool str_endswith | ( | const char * | str, |
const char * | suf | ||
) |
Check if a string ends with a suffix.
[in] | str | string |
[in] | suf | suffix |
Definition at line 57 of file gensvm_strutil.c.
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.
[in] | original | string you wish to split |
[in] | delims | string with delimiters to split on |
[out] | len_ret | length of the output array |
Definition at line 130 of file gensvm_strutil.c.
bool str_startswith | ( | const char * | str, |
const char * | pre | ||
) |
Check if a string starts with a prefix.
[in] | str | string |
[in] | pre | prefix |
Definition at line 42 of file gensvm_strutil.c.