stringfunctions.hh 2.87 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
/**
 * @brief ordinal convert character to its ordinal value
 * @param c char
 * @return integer
 */
25
int RADIX_PUBLIC ordinal(char c);
26
27
28
29
30
31
32

/**
 * @brief itoa converts integer into character
 * @param number integer must be within character bounds
 * @return char
 */
template <typename type = int>
33
char RADIX_PUBLIC itoa(type number);
34

35
36
37
38
39
40
41
/**
 * @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
 */
42
43
struct std::tm RADIX_PUBLIC utc_to_time(const std::string &time, int &zone,
                                        int &daylight);
44

45
46
47
48
/**
 * Convert a string to lowercase
 * @param the string to be converted
 */
49
std::string RADIX_PUBLIC string_tolower(const std::string &data);
50
51
52
53
54

/**
 * Convert a string to uppercase
 * @param the string to be converted
 */
55
std::string RADIX_PUBLIC string_toupper(const std::string &data);
56
57
58
59
60

/**
 * trim a leading and trailing whitespace
 * @param the string to be converted
 */
61
std::string RADIX_PUBLIC trim_string(const std::string &data);
62
63
64
65

/**
 * @brief Remove double- and single- quotes from the string
 */
66
std::string RADIX_PUBLIC strip_quotes(const std::string &src);
67
68
69
70
71

/**
 * @brief Convert something to a string.
 */
template <typename T>
72
std::string RADIX_PUBLIC to_string(const T &x, int prec = 6);
73
74
75
76
77

/**
 * @brief Convert something from a string using stream idioms.
 */
template <typename T>
78
T RADIX_PUBLIC from_string(const std::string &val, const T &defVal);
79
80
81
82
83

/**
 * @brief Join something like a vector to a single string with delimiter
 */
template <typename T>
84
std::string RADIX_PUBLIC join(const std::string &delim, const T &x);
85
86
87
88

/**
 * @brief Split a string into pieces using a delimiter
 */
89
90
91
std::vector<std::string> RADIX_PUBLIC
split_string(const std::string &delim, const std::string &word,
             bool removeEmptyParts = false);
92
93
94
95

/**
 * @brief Find all instances and replace them
 */
96
97
98
std::string RADIX_PUBLIC find_and_replace(const std::string &str,
                                          const std::string &find,
                                          const std::string &replace);
99
100
101
102

/**
 * @brief remove a particular substring (multiple times) from a target string
 */
103
std::string RADIX_PUBLIC remove_substring(const char *msg, const char *sub);
104
105
106
107

/**
 * @brief remove extra whitespace (\t-->' ', \n-->' ', '   '-->' ')
 */
108
std::string RADIX_PUBLIC remove_extra_whitespace(const std::string &str);
109
110
111
112
113
114
115

}  // namespace radix

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

#endif /** RADIX_RADIXCORE_STRINGFUNCTIONS_HH_ */