36 #include <boost/algorithm/string.hpp>
41 if (str.length() > 0) {
42 if (str.back() !=
'/') {
53 CHECK_EQ(ext.at(0),
'.');
54 std::string ext_lower = ext;
56 if (file_name.size() >= ext_lower.size() &&
57 file_name.substr(file_name.size() - ext_lower.size(), ext_lower.size()) ==
67 CHECK_GT(parts.size(), 0);
68 if (parts.size() == 1) {
73 for (
size_t i = 0; i < parts.size() - 1; ++i) {
74 *root += parts[i] +
".";
76 *root = root->substr(0, root->length() - 1);
77 if (parts.back() ==
"") {
80 *ext =
"." + parts.back();
85 void FileCopy(
const std::string& src_path,
const std::string& dst_path,
89 boost::filesystem::copy_file(src_path, dst_path);
92 boost::filesystem::create_hard_link(src_path, dst_path);
95 boost::filesystem::create_symlink(src_path, dst_path);
101 return boost::filesystem::is_regular_file(
path);
105 return boost::filesystem::is_directory(
path);
109 return boost::filesystem::exists(
path);
114 CHECK(boost::filesystem::create_directory(
path));
119 const std::vector<std::string> names =
121 if (names.size() > 1 && names.back() ==
"") {
122 return names[names.size() - 2];
137 using namespace boost::filesystem;
139 path from_path = canonical(
path(from));
145 path::const_iterator from_iter = from_path.begin();
146 path::const_iterator to_iter = to_path.begin();
149 while (from_iter != from_path.end() && to_iter != to_path.end() &&
150 (*to_iter) == (*from_iter)) {
157 while (from_iter != from_path.end()) {
163 while (to_iter != to_path.end()) {
164 rel_path /= *to_iter;
168 return rel_path.string();
172 std::vector<std::string> file_list;
173 for (
auto it = boost::filesystem::directory_iterator(
path);
174 it != boost::filesystem::directory_iterator(); ++it) {
175 if (boost::filesystem::is_regular_file(*it)) {
177 file_list.push_back(file_path.string());
184 std::vector<std::string> file_list;
185 for (
auto it = boost::filesystem::recursive_directory_iterator(
path);
186 it != boost::filesystem::recursive_directory_iterator(); ++it) {
187 if (boost::filesystem::is_regular_file(*it)) {
189 file_list.push_back(file_path.string());
196 std::vector<std::string> dir_list;
197 for (
auto it = boost::filesystem::directory_iterator(
path);
198 it != boost::filesystem::directory_iterator(); ++it) {
199 if (boost::filesystem::is_directory(*it)) {
201 dir_list.push_back(dir_path.string());
208 std::vector<std::string> dir_list;
209 for (
auto it = boost::filesystem::recursive_directory_iterator(
path);
210 it != boost::filesystem::recursive_directory_iterator(); ++it) {
211 if (boost::filesystem::is_directory(*it)) {
213 dir_list.push_back(dir_path.string());
220 std::ifstream file(
path, std::ifstream::ate | std::ifstream::binary);
221 CHECK(file.is_open()) <<
path;
233 std::cout << std::string(std::min<int>(heading.size(), 78),
'-') <<
std::endl;
239 std::vector<std::string> values;
240 values.reserve(elems.size());
241 for (
auto& elem : elems) {
246 values.push_back(elem);
252 std::vector<int>
CSVToVector(
const std::string& csv) {
254 std::vector<int> values;
255 values.reserve(elems.size());
256 for (
auto& elem : elems) {
262 values.push_back(std::stoi(elem));
263 }
catch (
const std::invalid_argument&) {
264 return std::vector<int>(0);
271 std::vector<float>
CSVToVector(
const std::string& csv) {
273 std::vector<float> values;
274 values.reserve(elems.size());
275 for (
auto& elem : elems) {
281 values.push_back(std::stod(elem));
282 }
catch (
const std::invalid_argument&) {
283 return std::vector<float>(0);
290 std::vector<double>
CSVToVector(
const std::string& csv) {
292 std::vector<double> values;
293 values.reserve(elems.size());
294 for (
auto& elem : elems) {
300 values.push_back(std::stold(elem));
301 }
catch (
const std::invalid_argument&) {
302 return std::vector<double>(0);
309 std::ifstream file(
path);
310 CHECK(file.is_open()) <<
path;
313 std::vector<std::string> lines;
314 while (std::getline(file, line)) {
321 lines.push_back(line);
328 for (
int i = 0; i < *argc; ++i) {
329 if (argv[i] == arg) {
330 for (
int j = i + 1; j < *argc; ++j) {
QTextStream & endl(QTextStream &stream)
static const std::string path
size_t GetFileSize(const std::string &path)
void PrintHeading2(const std::string &heading)
bool ExistsPath(const std::string &path)
void StringTrim(std::string *str)
bool HasFileExtension(const std::string &file_name, const std::string &ext)
std::vector< std::string > GetRecursiveFileList(const std::string &path)
std::vector< std::string > CSVToVector(const std::string &csv)
std::string StringReplace(const std::string &str, const std::string &old_str, const std::string &new_str)
std::string GetPathBaseName(const std::string &path)
void StringToLower(std::string *str)
std::string GetRelativePath(const std::string &from, const std::string &to)
void SplitFileExtension(const std::string &path, std::string *root, std::string *ext)
std::vector< std::string > ReadTextFileLines(const std::string &path)
bool ExistsDir(const std::string &path)
bool ExistsFile(const std::string &path)
void CreateDirIfNotExists(const std::string &path)
std::string EnsureTrailingSlash(const std::string &str)
void PrintHeading1(const std::string &heading)
std::vector< std::string > StringSplit(const std::string &str, const std::string &delim)
std::vector< std::string > GetRecursiveDirList(const std::string &path)
std::vector< std::string > GetFileList(const std::string &path)
std::string GetParentDir(const std::string &path)
void RemoveCommandLineArgument(const std::string &arg, int *argc, char **argv)
std::vector< std::string > GetDirList(const std::string &path)
void FileCopy(const std::string &src_path, const std::string &dst_path, CopyType type)