cmvr-es/include/utils/base/os.h

33 lines
825 B
C++

//
// Created by xtkuang on 2025/6/11.
//
#ifndef OS_H
#define OS_H
#include <vector>
#include <iostream>
#include <sys/stat.h>
inline bool pathExists(const std::string& path) {
struct stat info;
return stat(path.c_str(), &info) == 0;
}
inline std::vector<std::string> splitString(const std::string& pattern, const std::string& delimiter) {
std::vector<std::string> result;
if (delimiter.empty()) {
result.push_back(pattern); // 若分隔符为空,则原样返回
return result;
}
size_t start = 0;
size_t end;
while ((end = pattern.find(delimiter, start)) != std::string::npos) {
result.push_back(pattern.substr(start, end - start));
start = end + delimiter.length();
}
result.push_back(pattern.substr(start));
return result;
}
#endif //OS_H