You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
781 B
42 lines
781 B
#include "util.h" |
|
#include <string> |
|
#include <cstdlib> |
|
#include <cstdio> |
|
#include <istream> |
|
#include <fstream> |
|
#include <sstream> |
|
#include <iostream> |
|
|
|
namespace util { |
|
|
|
std::string |
|
trim_whitespace(std::string s) |
|
{ |
|
int ff = s.find_first_not_of(" \n\t"); |
|
int ll = s.find_last_not_of(" \n\t"); |
|
return s.substr(ff, ll - ff + 1); |
|
} |
|
|
|
|
|
|
|
std::string |
|
read_file(std::string const &fpath) |
|
{ |
|
std::ostringstream sstr; |
|
std::ifstream in (fpath); |
|
sstr << in.rdbuf(); |
|
return sstr.str(); |
|
} |
|
|
|
void write_file(std::string const &fpath, std::string const &content) { |
|
std::fstream s; |
|
s.open(fpath, std::ios_base::out); |
|
if (!s.is_open()) { |
|
std::cerr << "Error: failed to open file "<< fpath; |
|
return; |
|
} |
|
s << content; |
|
s.close(); |
|
} |
|
|
|
};
|
|
|