stringfunctions.hh 2.55 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
#ifndef RADIX_RADIXCORE_STRINGFUNCTIONS_HH_
#define RADIX_RADIXCORE_STRINGFUNCTIONS_HH_
/*
 * @file:   stringfunctions.hh
 * @author: Jordan P. Lefebvre
 *
 * Created on October 23, 2017, 16:34 PM
 */

#include <cstdio>
11
#include <ctime>
12
13
14
15
#include <fstream>
#include <string>
#include <vector>

16
#include "radixcore/visibility.hh"
17

18
19
namespace radix
{
20
21
22
23
24
25
26
/**
 * @brief utc_to_time UTC time to
 * @param time UTC formatted date and time
 * @param zone time zone
 * @param daylight daylight savings
 * @return struct tm
 */
27
28
struct std::tm RADIX_PUBLIC utc_to_time(const std::string &time, int &zone,
                                        int &daylight);
29

30
31
32
33
/**
 * Convert a string to lowercase
 * @param the string to be converted
 */
34
std::string RADIX_PUBLIC string_tolower(const std::string &data);
35
36
37
38
39

/**
 * Convert a string to uppercase
 * @param the string to be converted
 */
40
std::string RADIX_PUBLIC string_toupper(const std::string &data);
41
42
43
44
45

/**
 * trim a leading and trailing whitespace
 * @param the string to be converted
 */
46
std::string RADIX_PUBLIC trim_string(const std::string &data);
47
48
49
50

/**
 * @brief Remove double- and single- quotes from the string
 */
51
std::string RADIX_PUBLIC strip_quotes(const std::string &src);
52
53
54
55
56

/**
 * @brief Convert something to a string.
 */
template <typename T>
57
std::string RADIX_PUBLIC to_string(const T &x, int prec = 6);
58
59
60
61
62

/**
 * @brief Convert something from a string using stream idioms.
 */
template <typename T>
63
T RADIX_PUBLIC from_string(const std::string &val, const T &defVal);
64
65
66
67
68

/**
 * @brief Join something like a vector to a single string with delimiter
 */
template <typename T>
69
std::string RADIX_PUBLIC join(const std::string &delim, const T &x);
70
71
72
73

/**
 * @brief Split a string into pieces using a delimiter
 */
74
75
std::vector<std::string> RADIX_PUBLIC split_string(const std::string &delim,
                                                   const std::string &word);
76
77
78
79

/**
 * @brief Find all instances and replace them
 */
80
81
82
std::string RADIX_PUBLIC find_and_replace(const std::string &str,
                                          const std::string &find,
                                          const std::string &replace);
83
84
85
86

/**
 * @brief remove a particular substring (multiple times) from a target string
 */
87
std::string RADIX_PUBLIC remove_substring(const char *msg, const char *sub);
88
89
90
91

/**
 * @brief remove extra whitespace (\t-->' ', \n-->' ', '   '-->' ')
 */
92
std::string RADIX_PUBLIC remove_extra_whitespace(const std::string &str);
93
94
95
96
97
98
99

}  // namespace radix

//! Templated functions
#include "stringfunctions.i.hh"

#endif /** RADIX_RADIXCORE_STRINGFUNCTIONS_HH_ */