2025-05-20 15:39:40 +08:00
|
|
|
#include "XNCore_global.h"
|
|
|
|
|
2025-05-27 15:16:11 +08:00
|
|
|
namespace XNSim
|
|
|
|
{
|
2025-05-20 15:39:40 +08:00
|
|
|
XNTimePoint parseISOTime(const std::string &timeStr)
|
|
|
|
{
|
|
|
|
std::tm tm = {};
|
|
|
|
std::istringstream ss(timeStr);
|
|
|
|
ss >> std::get_time(&tm, "%Y-%m-%dT%H:%M:%S");
|
|
|
|
auto tp = std::chrono::system_clock::from_time_t(std::mktime(&tm));
|
|
|
|
return tp;
|
2025-05-27 15:16:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// 辅助函数:分割字符串
|
|
|
|
std::vector<std::string> split(const std::string &str, const std::string &delim)
|
|
|
|
{
|
|
|
|
std::vector<std::string> tokens;
|
|
|
|
size_t prev = 0, pos = 0;
|
|
|
|
do {
|
|
|
|
pos = str.find(delim, prev);
|
|
|
|
if (pos == std::string::npos)
|
|
|
|
pos = str.length();
|
|
|
|
std::string token = str.substr(prev, pos - prev);
|
|
|
|
if (!token.empty())
|
|
|
|
tokens.push_back(token);
|
|
|
|
prev = pos + delim.length();
|
|
|
|
} while (pos < str.length() && prev < str.length());
|
|
|
|
return tokens;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 辅助函数:获取文件名(不含扩展名)
|
|
|
|
std::string getFileNameWithoutExt(const std::string &path)
|
|
|
|
{
|
|
|
|
size_t lastDot = path.find_last_of('.');
|
|
|
|
if (lastDot != std::string::npos) {
|
|
|
|
return path.substr(0, lastDot);
|
|
|
|
}
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 安全地将字符串转换为整数
|
|
|
|
* @param str 要转换的字符串
|
|
|
|
* @param defaultValue 转换失败时的默认值
|
|
|
|
* @return 转换后的整数值
|
|
|
|
*/
|
|
|
|
int safe_stoi(const std::string &str, int defaultValue)
|
|
|
|
{
|
|
|
|
if (str.empty()) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
return std::stoi(str);
|
|
|
|
} catch (const std::exception &) {
|
|
|
|
return defaultValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace XNSim
|