new-feature:1.添加带表达式内容的xml格式化。2.支持带特殊字符的读写,如& < > "。

This commit is contained in:
2024-09-14 00:02:48 +08:00
parent bb511d1bac
commit 6896fa5090
20 changed files with 332 additions and 95 deletions

View File

@@ -1,4 +1,5 @@
#include "public_def.h"
#include <QFileDialog>
#include <QMessageBox>
@@ -11,7 +12,8 @@ void CUtil::msg(QWidget* parent, const QString& content)
QMessageBox::information(parent, u8"提示", content);
}
bool CUtil::affirm(QWidget* parent, const QString& titile, const QString& content)
bool CUtil::affirm(QWidget* parent, const QString& titile,
const QString& content)
{
QMessageBox questionBox(parent);
questionBox.setText(content);
@@ -26,9 +28,11 @@ bool CUtil::affirm(QWidget* parent, const QString& titile, const QString& conten
}
}
QString CUtil::select_file(QWidget* parent, const QString& info, const QString& filter)
QString CUtil::select_file(QWidget* parent, const QString& info,
const QString& filter)
{
QString filePath = QFileDialog::getOpenFileName(parent, info, QDir::homePath(), filter);
QString filePath =
QFileDialog::getOpenFileName(parent, info, QDir::homePath(), filter);
return filePath;
}
@@ -58,22 +62,26 @@ void CUtil::sort_by_repeat(std::vector<std::string>& vec)
std::string CUtil::utf8_to_gbk(const std::string& utf8_str)
{
// UTF-8 to Wide Char (UTF-16)
int wide_char_len = MultiByteToWideChar(CP_UTF8, 0, utf8_str.c_str(), -1, nullptr, 0);
int wide_char_len =
MultiByteToWideChar(CP_UTF8, 0, utf8_str.c_str(), -1, nullptr, 0);
if (wide_char_len == 0) {
return "";
}
std::wstring wide_str(wide_char_len, 0);
MultiByteToWideChar(CP_UTF8, 0, utf8_str.c_str(), -1, &wide_str[0], wide_char_len);
MultiByteToWideChar(CP_UTF8, 0, utf8_str.c_str(), -1, &wide_str[0],
wide_char_len);
// Wide Char (UTF-16) to GBK
int gbk_len = WideCharToMultiByte(CP_ACP, 0, wide_str.c_str(), -1, nullptr, 0, nullptr, nullptr);
int gbk_len = WideCharToMultiByte(CP_ACP, 0, wide_str.c_str(), -1, nullptr,
0, nullptr, nullptr);
if (gbk_len == 0) {
return "";
}
std::string gbk_str(gbk_len, 0);
WideCharToMultiByte(CP_ACP, 0, wide_str.c_str(), -1, &gbk_str[0], gbk_len, nullptr, nullptr);
WideCharToMultiByte(CP_ACP, 0, wide_str.c_str(), -1, &gbk_str[0], gbk_len,
nullptr, nullptr);
return gbk_str;
}
@@ -84,7 +92,8 @@ std::string CUtil::utf8_to_gbk(const std::string& utf8_str)
}
#endif
std::vector<std::string> CUtil::splitString(const std::string& input, const std::string& delimiter)
std::vector<std::string> CUtil::splitString(const std::string& input,
const std::string& delimiter)
{
std::vector<std::string> tokens;
size_t pos = 0;