TECA
The Toolkit for Extreme Climate Analysis
teca_string_util.h File Reference
#include "teca_common.h"
#include <cstdlib>
#include <cstring>
#include <cerrno>
#include <string>
#include <vector>
#include <set>
Include dependency graph for teca_string_util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  teca_string_util::scanf_tt< num_t >
 A traits class for scanf conversion codes. More...
 
struct  teca_string_util::scanf_tt< float >
 
struct  teca_string_util::scanf_tt< double >
 
struct  teca_string_util::scanf_tt< char >
 
struct  teca_string_util::scanf_tt< short >
 
struct  teca_string_util::scanf_tt< int >
 
struct  teca_string_util::scanf_tt< long >
 
struct  teca_string_util::scanf_tt< long long >
 
struct  teca_string_util::scanf_tt< unsigned char >
 
struct  teca_string_util::scanf_tt< unsigned short >
 
struct  teca_string_util::scanf_tt< unsigned int >
 
struct  teca_string_util::scanf_tt< unsigned long >
 
struct  teca_string_util::scanf_tt< unsigned long long >
 
struct  teca_string_util::scanf_tt< std::string >
 
struct  teca_string_util::string_tt< T >
 A traits class for conversion from text to numbers. More...
 
struct  teca_string_util::string_tt< float >
 
struct  teca_string_util::string_tt< double >
 
struct  teca_string_util::string_tt< char >
 
struct  teca_string_util::string_tt< short >
 
struct  teca_string_util::string_tt< int >
 
struct  teca_string_util::string_tt< long >
 
struct  teca_string_util::string_tt< long long >
 
struct  teca_string_util::string_tt< bool >
 A traits class for conversion from text to numbers, specialized for bool. More...
 
struct  teca_string_util::string_tt< std::string >
 A traits class for conversion from text to numbers, specialized for std::string. More...
 
struct  teca_string_util::string_tt< char * >
 

Namespaces

 teca_string_util
 Codes for dealing with string processing.
 

Macros

#define DECLARE_SCANF_TT(_CPP_T, _FMT_STR)
 
#define DECLARE_STR_CONVERSION_I(_CPP_T, _FUNC)
 
#define DECLARE_STR_CONVERSION_F(_CPP_T, _FUNC)
 

Functions

int teca_string_util::extract_string (const char *istr, std::string &field)
 
int teca_string_util::tokenize (char *istr, char delim, int n_cols, char **ostr)
 
template<typename container_t = std::vector<char*>>
int teca_string_util::tokenize (char *istr, char delim, container_t &ostr)
 
int teca_string_util::skip_pad (char *&buf)
 
int teca_string_util::is_comment (char *buf)
 return 0 if the first non-pad character is # More...
 
template<typename val_t >
int teca_string_util::extract_value (char *l, val_t &val)
 
void teca_string_util::remove_post_fix (std::set< std::string > &names, std::string post_fix)
 
std::string teca_string_util::emptystr (const std::string &in)
 When passed the string "" return empty string otherwise return the passed string. More...
 

Macro Definition Documentation

◆ DECLARE_SCANF_TT

#define DECLARE_SCANF_TT (   _CPP_T,
  _FMT_STR 
)
Value:
template<> \
/** A traits class for scanf conversion codes, specialized fo _CPP_T */ \
struct scanf_tt<_CPP_T> \
{ \
static \
const char *format() { return _FMT_STR; } \
};

◆ DECLARE_STR_CONVERSION_F

#define DECLARE_STR_CONVERSION_F (   _CPP_T,
  _FUNC 
)
Value:
/** A traits class for conversion from text to numbers, specialized for _CPP_T */ \
template <> \
struct string_tt<_CPP_T> \
{ \
static const char *type_name() { return # _CPP_T; } \
\
static int convert(const char *str, _CPP_T &val) \
{ \
errno = 0; \
char *endp = nullptr; \
_CPP_T tmp = _FUNC(str, &endp); \
if (errno != 0) \
{ \
TECA_ERROR("Failed to convert string \"" \
<< str << "\" to a nunber." << strerror(errno)) \
return -1; \
} \
else if (endp == str) \
{ \
TECA_ERROR("Failed to convert string \"" \
<< str << "\" to a nunber. Invalid string.") \
return -1; \
} \
val = tmp; \
return 0; \
} \
};

◆ DECLARE_STR_CONVERSION_I

#define DECLARE_STR_CONVERSION_I (   _CPP_T,
  _FUNC 
)
Value:
/** A traits class for conversion from text to numbers, specialized for _CPP_T */ \
template <> \
struct string_tt<_CPP_T> \
{ \
static const char *type_name() { return # _CPP_T; } \
\
static int convert(char *str, _CPP_T &val) \
{ \
errno = 0; \
char *endp = nullptr; \
_CPP_T tmp = _FUNC(str, &endp, 0); \
if (errno != 0) \
{ \
TECA_ERROR("Failed to convert string \"" \
<< str << "\" to a nunber." << strerror(errno)) \
return -1; \
} \
else if (endp == str) \
{ \
TECA_ERROR("Failed to convert string \"" \
<< str << "\" to a nunber. Invalid string.") \
return -1; \
} \
val = tmp; \
return 0; \
} \
};