Repository navigation
Expand file tree
/
Copy pathstring_misc.hpp
More file actions
executable file
·155 lines (123 loc) · 3.35 KB
/
Copy pathstring_misc.hpp
File metadata and controls
executable file
·155 lines (123 loc) · 3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#ifndef STRING_MISC_H
#define STRING_MISC_H
#include "library.hpp"
namespace str
{
/**
* @brief split Split a line according to a specific seperator
*
* @param line
* String to be split
* @param separator
* Character or string to use for the split
* @param list
* Either input or return variable of the function in which the
* splitted portions of the line are stored.
*/
std::vector<std::string> &split( std::string const& line, std::string const& separator, std::vector<std::string> &list );
std::vector<std::string> split( std::string const& line, std::string const& separator );
std::vector<std::string> split( std::string const& line, const char* separator );
/**
* @brief split Split a line according to a specific seperator
*
* @param line
* String to be split
* @param separator
* Character or string to use for the split
* @param list
* Either input or return variable of the function in which the
* splitted portions of the line are stored.
*/
std::vector<std::string> &split( std::string const& line, std::string const& separator, std::vector<std::string> &list )
{
// Vector initialization
list.clear();
// Index initialization
size_t start(0);
size_t end(0);
// Iteration to split line string
while( end!= std::string::npos )
{
end = line.find( separator, start );
// Get the new item
list.push_back( line.substr( start, end - start ) );
start = end + separator.size();
}
return list;
}
std::vector<std::string> split( std::string const& line, std::string const& separator )
{
std::vector<std::string> list;
return split( line, separator, list );
}
std::vector<std::string> split( std::string const& line, const char* separator )
{
return split( line, std::string(separator) );
}
/**
* @brief Misceallenous function to identity the type of character.
*
*/
inline bool is_whitespace(const char c)
{
return (' ' == c) || ('\n' == c) ||
('\r' == c) || ('\t' == c) ||
('\b' == c) || ('\v' == c) ||
('\f' == c) ;
}
inline bool is_operator_char(const char c)
{
return ('+' == c) || ('-' == c) ||
('*' == c) || ('/' == c) ||
('^' == c) || ('<' == c) ||
('>' == c) || ('=' == c) ||
(',' == c) || ('!' == c) ||
('(' == c) || (')' == c) ||
('[' == c) || (']' == c) ||
('{' == c) || ('}' == c) ||
('%' == c) || (':' == c) ||
('?' == c) || ('&' == c) ||
('|' == c) || (';' == c) ;
}
inline bool is_math_operator(const char c)
{
return ('+' == c) || ('-' == c) ||
('*' == c) || ('/' == c) ;
}
inline bool is_letter(const char c)
{
return (('a' <= c) && (c <= 'z')) ||
(('A' <= c) && (c <= 'Z')) ;
}
inline bool is_digit(const char c)
{
return ('0' <= c) && (c <= '9');
}
inline bool is_letter_or_digit(const char c)
{
return is_letter(c) || is_digit(c);
}
inline bool is_left_bracket(const char c)
{
return ('(' == c) || ('[' == c) || ('{' == c);
}
inline bool is_left_bracket(const std::string s)
{
if( s.size() != 1 )
return false;
else return is_left_bracket( s[0] );
}
inline bool is_right_bracket(const char c)
{
return (')' == c) || (']' == c) || ('}' == c);
}
inline bool is_bracket(const char c)
{
return is_left_bracket(c) || is_right_bracket(c);
}
inline bool is_sign(const char c)
{
return ('+' == c) || ('-' == c);
}
}
#endif // STRING_MISC_H