25#ifndef __BITPIT_STRING_UTILS_TPP__
26#define __BITPIT_STRING_UTILS_TPP__
46inline std::string &
ltrim(std::string &s)
56 s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](
unsigned char c){ return !std::isspace(c); }));
72inline std::string &
rtrim(std::string &s)
82 s.erase(std::find_if(s.rbegin(), s.rend(), [](
unsigned char c){ return !std::isspace(c); }).base(), s.end());
98inline std::string &
trim(std::string &s)
115inline std::string
lfill(
int nchars,
const std::string &s,
char c)
117 std::stringstream ss;
118 ss << std::string(nchars - s.length(), c) << s;
135inline std::string
rfill(
int nchars,
const std::string &s,
char c)
137 std::stringstream ss;
138 ss << s << std::string(nchars - s.length(), c);
160 std::ostringstream ss;
161 ss << std::setw(nchars) << std::setfill(
'0') << num;
177 return (line.find(key) != std::string::npos);
198 std::stringstream ss(input);
207 if (tmp.size() == 0) {
208 std::cout <<
" no useful information in string " << input << std::endl;
209 std::cout <<
" casting zero " << std::endl;
211 x =
static_cast<T
> (0);
212 }
else if (tmp.size() == 1) {
214 }
else if(tmp.size() > 1) {
215 std::cout <<
" more than one element in string " << input << std::endl;
216 std::cout <<
" assigning first element " << std::endl;
242 std::stringstream ss(input);
251 if (tmp.size() == 0) {
252 std::cout <<
" no useful information in string " << input << std::endl;
253 std::cout <<
" returning void vector " << std::endl;
273template <
class T,
size_t n>
282 std::stringstream ss(input);
289 if (tmp.size() < n) {
290 std::cout <<
" not enough useful information in string " << input << std::endl;
291 std::cout <<
" casting zero into missing elements " << std::endl;
293 x =
static_cast<T
>(0);
296 for(
size_t i=0; i<tmp.size(); i++) {
299 }
else if (tmp.size() == n) {
300 for(
size_t i = 0; i < n; i++) {
303 }
else if (tmp.size() > n) {
304 std::cout <<
" more than " << n <<
" elements in string " << input << std::endl;
305 std::cout <<
" assigning first element " << n <<
" elements " << std::endl;
307 for(
size_t i = 0; i < n; i++) {
std::string & trim(std::string &s)
std::string rfill(int nchars, const std::string &s, char c)
std::string zeroPadNumber(int nchars, int num)
std::string & ltrim(std::string &s)
bool keywordInString(const std::string &line, const std::string &key)
std::string lfill(int nchars, const std::string &s, char c)
void convertString(std::string input, T &output)
std::string & rtrim(std::string &s)