2024-05-15 10:59:43 +08:00
|
|
|
#include "public_def.h"
|
2024-05-15 17:34:07 +08:00
|
|
|
#include <QMessageBox>
|
2024-05-17 22:46:33 +08:00
|
|
|
#include <QFileDialog>
|
2024-05-15 10:59:43 +08:00
|
|
|
|
2024-05-15 23:06:48 +08:00
|
|
|
std::vector<std::string> splitString(const std::string& input, const std::string& delimiter)
|
|
|
|
{
|
2024-05-15 10:59:43 +08:00
|
|
|
std::vector<std::string> tokens;
|
2024-05-15 23:06:48 +08:00
|
|
|
size_t pos = 0;
|
|
|
|
std::string backup = input;
|
|
|
|
std::string token;
|
|
|
|
|
2024-05-15 10:59:43 +08:00
|
|
|
while ((pos = backup.find(delimiter)) != std::string::npos) {
|
|
|
|
token = backup.substr(0, pos);
|
|
|
|
tokens.push_back(token);
|
|
|
|
backup.erase(0, pos + delimiter.length());
|
|
|
|
}
|
|
|
|
// Push the remaining part after the last delimiter
|
|
|
|
tokens.push_back(backup);
|
|
|
|
|
|
|
|
return tokens;
|
2024-05-15 17:34:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CUtil::msg(QWidget* parent, const QString& content)
|
|
|
|
{
|
|
|
|
QMessageBox::information(parent, u8"提示", content);
|
|
|
|
}
|
2024-05-15 23:06:48 +08:00
|
|
|
|
|
|
|
bool CUtil::affirm(QWidget* parent, const QString& titile, const QString& content)
|
|
|
|
{
|
|
|
|
QMessageBox questionBox(parent);
|
|
|
|
questionBox.setText(content);
|
|
|
|
questionBox.setWindowTitle(titile);
|
|
|
|
questionBox.setIcon(QMessageBox::Question);
|
|
|
|
questionBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
|
|
|
int result = questionBox.exec();
|
|
|
|
if (result != QMessageBox::Yes) {
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2024-05-17 22:46:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
QString CUtil::select_file(QWidget* parent, const QString& info, const QString& filter)
|
|
|
|
{
|
|
|
|
QString filePath =
|
|
|
|
QFileDialog::getOpenFileName(parent, info, QDir::homePath(), filter);
|
|
|
|
return filePath;
|
|
|
|
}
|
2024-05-18 01:26:52 +08:00
|
|
|
|
|
|
|
void CUtil::sort_by_repeat(std::vector<std::string>& vec)
|
|
|
|
{
|
|
|
|
std::size_t len1 = 0;
|
|
|
|
std::size_t len2 = 0;
|
|
|
|
std::size_t cur = 0;
|
|
|
|
auto compare = [&](const std::string& str1, const std::string& str2) {
|
|
|
|
len1 = str1.size();
|
|
|
|
len2 = str2.size();
|
|
|
|
if (cur >= len1 || cur >= len2) {
|
|
|
|
return len1 > len2;
|
|
|
|
}
|
|
|
|
return str1[cur] > str2[cur];
|
|
|
|
};
|
|
|
|
std::size_t max_len = 0;
|
|
|
|
for (const auto& data : vec) {
|
|
|
|
max_len = data.size() > max_len ? data.size() : max_len;
|
|
|
|
}
|
|
|
|
for (cur = 0; cur < max_len; ++cur) {
|
|
|
|
std::sort(vec.begin(), vec.end(), compare);
|
|
|
|
}
|
|
|
|
}
|